Skip to content

Commit a8acbb9

Browse files
committed
Add -h option to all commands and cover it with tests
1 parent 81e0953 commit a8acbb9

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,20 @@ ALTER SESSION SET NLS_TERRITORY='AMERICA';
5555
```
5656

5757
## Usage
58-
Currently, utPLSQL-cli supports the following commands:
58+
Currently, utPLSQL-cli supports the following sub-commands:
5959
- run
6060
- info
6161
- reporters
62+
- help
63+
64+
To get more info about a command, use
65+
```
66+
utplsql <sub-command> -h
67+
```
68+
Example:
69+
```
70+
utplsql run -h
71+
```
6272

6373
#### \<ConnectionURL>
6474

src/main/java/org/utplsql/cli/ReportersCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.utplsql.api.reporter.inspect.ReporterInspector;
88
import org.utplsql.cli.exception.DatabaseConnectionFailed;
99
import picocli.CommandLine.Command;
10+
import picocli.CommandLine.Option;
1011
import picocli.CommandLine.Parameters;
1112

1213
import javax.sql.DataSource;
@@ -22,6 +23,9 @@ public class ReportersCommand implements ICommand {
2223
@Parameters(description = UtplsqlPicocliCommand.COMMANDLINE_PARAM_DESCRIPTION, arity = "1")
2324
private String connectionString;
2425

26+
@Option(names = "-h", usageHelp = true, description = "display this help and exit")
27+
boolean help;
28+
2529
@Override
2630
public int run() {
2731

src/main/java/org/utplsql/cli/VersionInfoCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.utplsql.api.db.DefaultDatabaseInformation;
77
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
88
import picocli.CommandLine.Command;
9+
import picocli.CommandLine.Option;
910
import picocli.CommandLine.Parameters;
1011

1112
import javax.sql.DataSource;
@@ -18,6 +19,9 @@ public class VersionInfoCommand implements ICommand {
1819
@Parameters(description = UtplsqlPicocliCommand.COMMANDLINE_PARAM_DESCRIPTION, arity = "0..1")
1920
private String connectionString;
2021

22+
@Option(names = "-h", usageHelp = true, description = "display this help and exit")
23+
boolean help;
24+
2125
public int run() {
2226

2327
System.out.println(CliVersionInfo.getInfo());

src/test/java/org/utplsql/cli/CliHelpTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,36 @@ void show_basic_help_on_help_command() {
2020
assertTrue(output.contains("Usage:"));
2121
}
2222

23+
@Test
24+
void show_help_for_run_command() {
25+
capturer = new SystemCapturer.SystemOutCapturer();
26+
capturer.start();
27+
TestHelper.runApp("run", "-h");
28+
String output = capturer.stop();
29+
30+
assertTrue(output.contains("Usage:"));
31+
}
32+
33+
@Test
34+
void show_help_for_reporters_command() {
35+
capturer = new SystemCapturer.SystemOutCapturer();
36+
capturer.start();
37+
TestHelper.runApp("reporters", "-h");
38+
String output = capturer.stop();
39+
40+
assertTrue(output.contains("Usage:"));
41+
}
42+
43+
@Test
44+
void show_help_for_info_command() {
45+
capturer = new SystemCapturer.SystemOutCapturer();
46+
capturer.start();
47+
TestHelper.runApp("reporters", "-h");
48+
String output = capturer.stop();
49+
50+
assertTrue(output.contains("Usage:"));
51+
}
52+
2353
@Test
2454
void write_help_to_error_out_on_unknown_command() {
2555
capturer = new SystemCapturer.SystemErrCapturer();

0 commit comments

Comments
 (0)