-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathCli.java
More file actions
61 lines (41 loc) · 1.54 KB
/
Cli.java
File metadata and controls
61 lines (41 loc) · 1.54 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
55
56
57
58
59
60
61
package org.utplsql.cli;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import org.utplsql.api.exception.DatabaseNotCompatibleException;
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
import org.utplsql.cli.exception.DatabaseConnectionFailed;
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 ) {
LocaleInitializer.initLocale();
JCommander jc = new JCommander();
jc.setProgramName("utplsql");
CommandProvider cmdProvider = new CommandProvider();
cmdProvider.commands().forEach(cmd -> jc.addCommand(cmd.getCommand(), cmd));
int exitCode = DEFAULT_ERROR_CODE;
try {
jc.parse(args);
exitCode = cmdProvider.getCommand(jc.getParsedCommand()).run();
} catch (ParameterException e) {
if (jc.getParsedCommand() != null) {
System.err.println(e.getMessage());
jc.usage(jc.getParsedCommand());
} else {
jc.usage();
}
} catch (Exception e) {
e.printStackTrace();
}
return exitCode;
}
private static class HelpCommand {
@Parameter(names = {HELP_CMD, "--help"}, help = true)
public boolean callHelp;
}
}