forked from utPLSQL/utPLSQL-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCli.java
More file actions
51 lines (38 loc) · 1.33 KB
/
Cli.java
File metadata and controls
51 lines (38 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.utplsql.cli;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
public class Cli {
public static final int DEFAULT_ERROR_CODE = 1;
public static final String HELP_CMD = "-h";
public static final String RUN_CMD = "run";
public static void main(String[] args) {
JCommander jc = new JCommander();
// jc.addCommand(HELP_CMD, new HelpCommand());
RunCommand runCmd = new RunCommand();
jc.addCommand(RUN_CMD, runCmd);
int exitCode = DEFAULT_ERROR_CODE;
try {
jc.parse(args);
if (RUN_CMD.equals(jc.getParsedCommand())) {
exitCode = runCmd.run();
} else {
throw new ParameterException("Command not specified.");
}
} catch (ParameterException e) {
if (jc.getParsedCommand() != null) {
System.err.println(e.getMessage());
jc.usage(jc.getParsedCommand());
} else {
jc.usage();
}
} catch (Exception e) {
e.printStackTrace();
}
System.exit(exitCode);
}
private static class HelpCommand {
@Parameter(names = {HELP_CMD, "--help"}, help = true)
public boolean callHelp;
}
}