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
54 lines (36 loc) · 1.3 KB
/
Cli.java
File metadata and controls
54 lines (36 loc) · 1.3 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
52
53
54
package org.utplsql.cli;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
public class Cli {
static final int DEFAULT_ERROR_CODE = 1;
static final String HELP_CMD = "-h";
public static void main(String[] args) {
int exitCode = runWithExitCode(args);
System.exit(exitCode);
}
static int runWithExitCode( String[] args ) {
LoggerConfiguration.configure(LoggerConfiguration.ConfigLevel.NONE);
LocaleInitializer.initLocale();
JCommander jc = new JCommander();
jc.setProgramName("utplsql");
CommandProvider cmdProvider = new CommandProvider(jc);
cmdProvider.commands().forEach(cmd -> jc.addCommand(cmd.getCommand(), cmd));
int exitCode = DEFAULT_ERROR_CODE;
if ( args.length >= 1 && args[0].equals("-h") ) // Help?
{
exitCode = 0;
jc.usage();
}
else {
try {
jc.parse(args);
exitCode = cmdProvider.getCommand(jc.getParsedCommand()).run();
} catch (ParameterException e) {
exitCode = new HelpCommand(jc, e.getMessage()).run();
} catch (Exception e) {
e.printStackTrace();
}
}
return exitCode;
}
}