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
62 lines (45 loc) · 1.7 KB
/
Cli.java
File metadata and controls
62 lines (45 loc) · 1.7 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
62
package org.utplsql.cli;
import picocli.CommandLine;
import java.util.List;
public class Cli {
static final int DEFAULT_ERROR_CODE = 1;
public static void main(String[] args) {
int exitCode = runPicocliWithExitCode(args);
System.exit(exitCode);
}
static int runPicocliWithExitCode(String[] args) {
CommandLine commandLine = new CommandLine(UtplsqlPicocliCommand.class);
commandLine.setTrimQuotes(true);
int exitCode = DEFAULT_ERROR_CODE;
try {
List<CommandLine> parsedLines = commandLine.parse(args);
boolean commandWasRun = false;
for (CommandLine parsedLine : parsedLines) {
if (parsedLine.isUsageHelpRequested()) {
parsedLine.usage(System.out);
return 0;
} else if (parsedLine.isVersionHelpRequested()) {
parsedLine.printVersionHelp(System.out);
return 0;
}
Object command = parsedLine.getCommand();
if (command instanceof ICommand) {
exitCode = ((ICommand) command).run();
commandWasRun = true;
break;
}
}
if (!commandWasRun) {
commandLine.usage(System.out);
}
} catch (CommandLine.ParameterException e) {
System.err.println(e.getMessage());
if (!CommandLine.UnmatchedArgumentException.printSuggestions(e, System.err)) {
e.getCommandLine().usage(System.err);
}
} catch (Exception e) {
e.printStackTrace();
}
return exitCode;
}
}