Skip to content

Commit

Permalink
[SQLLINE-142] Add missed '-e' option in '--help' output
Browse files Browse the repository at this point in the history
Add usage of -e option in tests to skip useless prompt output in logs.
  • Loading branch information
snuyanzin authored and julianhyde committed Oct 2, 2018
1 parent c222391 commit 4689fa7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/sqlline/SqlLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ public void handleException(Throwable e) {
error(e.getMessage());
}
} else {
e.printStackTrace(System.err);
e.printStackTrace(getErrorStream());
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/sqlline/SqlLine.properties
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ cmd-usage: Usage: java sqlline.SqlLine \n \
\ -n <username> the username to connect as\n \
\ -p <password> the password to connect as\n \
\ -d <driver class> the driver class to use\n \
\ -e <command> the command to execute\n \
\ -nn <nickname> nickname for the connection\n \
\ -ch <command handler>[,<command handler>]* a custom command handler to use\n \
\ -f <file> script file to execute (same as --run)\n \
Expand Down
18 changes: 12 additions & 6 deletions src/test/java/sqlline/SqlLineArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ public void testCommandHandlerOnStartup() throws IOException {
sqlLine.setErrorStream(sqllineOutputStream);
final InputStream is = new ByteArrayInputStream(new byte[0]);
final String[] args = {
"-e", "!set maxwidth 80",
"-ch", "sqlline.extensions.HelloWorldCommandHandler"};
sqlLine.begin(args, is, false);

Expand Down Expand Up @@ -838,7 +839,8 @@ public void testCommandHandler() throws IOException {
sqlLine.setOutputStream(sqllineOutputStream);
sqlLine.setErrorStream(sqllineOutputStream);
final InputStream is = new ByteArrayInputStream(new byte[0]);
SqlLine.Status status = sqlLine.begin(new String[]{}, is, false);
SqlLine.Status status =
sqlLine.begin(new String[]{"-e", "!set maxwidth 80"}, is, false);

final String script = "!commandhandler"
+ " sqlline.extensions.HelloWorld2CommandHandler"
Expand Down Expand Up @@ -1067,7 +1069,8 @@ public void testConnectWithDbPropertyAsParameter() throws Throwable {
beeLine.setOutputStream(beelineOutputStream);
beeLine.setErrorStream(beelineOutputStream);
final InputStream is = new ByteArrayInputStream(new byte[0]);
SqlLine.Status status = beeLine.begin(new String[]{}, is, false);
SqlLine.Status status =
beeLine.begin(new String[]{"-e", "!set maxwidth 80"}, is, false);
assertThat(status, equalTo(SqlLine.Status.OK));
DispatchCallback dc = new DispatchCallback();
beeLine.runCommands(Collections.singletonList("!set maxwidth 80"), dc);
Expand Down Expand Up @@ -1107,7 +1110,8 @@ public void testConnectWithDbPropertyAsParameter2() throws Throwable {
beeLine.setOutputStream(beelineOutputStream);
beeLine.setErrorStream(beelineOutputStream);
final InputStream is = new ByteArrayInputStream(new byte[0]);
SqlLine.Status status = beeLine.begin(new String[]{}, is, false);
SqlLine.Status status =
beeLine.begin(new String[]{"-e", "!set maxwidth 80"}, is, false);
assertThat(status, equalTo(SqlLine.Status.OK));
DispatchCallback dc = new DispatchCallback();
beeLine.runCommands(Collections.singletonList("!set maxwidth 80"), dc);
Expand Down Expand Up @@ -1144,7 +1148,8 @@ public void testConnectWithDbProperty() throws Throwable {
beeLine.setOutputStream(beelineOutputStream);
beeLine.setErrorStream(beelineOutputStream);
final InputStream is = new ByteArrayInputStream(new byte[0]);
SqlLine.Status status = beeLine.begin(new String[]{}, is, false);
SqlLine.Status status =
beeLine.begin(new String[]{"-e", "!set maxwidth 80"}, is, false);
assertThat(status, equalTo(SqlLine.Status.OK));
DispatchCallback dc = new DispatchCallback();
beeLine.runCommands(Collections.singletonList("!set maxwidth 80"), dc);
Expand Down Expand Up @@ -1341,15 +1346,16 @@ public void testAppInfoMessage() throws Throwable {
assertThat(pair.output,
containsString(Application.DEFAULT_APP_INFO_MESSAGE));

String[] args = {"-ac", "INCORRECT_CLASS_NAME"};
String[] args = {"-e", "!set maxwidth 80", "-ac", "INCORRECT_CLASS_NAME"};
pair = run(args);
assertThat(pair.status, equalTo(SqlLine.Status.OK));
assertThat(pair.output,
containsString("Could not initialize INCORRECT_CLASS_NAME"));
assertThat(pair.output,
containsString(CustomApplication.DEFAULT_APP_INFO_MESSAGE));

String[] args2 = {"-ac", "sqlline.extensions.CustomApplication"};
String[] args2 = {"-e", "!set maxwidth 80",
"-ac", "sqlline.extensions.CustomApplication"};
pair = run(args2);
assertThat(pair.status, equalTo(SqlLine.Status.OK));
assertThat(pair.output,
Expand Down

0 comments on commit 4689fa7

Please sign in to comment.