forked from sourcegraph/scip-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgumentParser.java
More file actions
97 lines (78 loc) · 2.9 KB
/
ArgumentParser.java
File metadata and controls
97 lines (78 loc) · 2.9 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import org.apache.commons.cli.*;
public class ArgumentParser {
public static final String VERSION = "0.1.0";
public static final String PROTOCOL_VERSION = "0.4.0";
public static Arguments parse(String[] args) {
Options options = createOptions();
CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
formatter.printHelp("lsif-java", "lsif-java is an LSIF indexer for Java.\n\n", options, "");
System.exit(1);
return null;
}
if (cmd.hasOption("help")) {
formatter.printHelp("lsif-java", "lsif-java is an LSIF indexer for Java.\n\n", options, "");
System.exit(0);
}
if (cmd.hasOption("version")) {
System.out.printf("%s, protocol version %s\n", VERSION, PROTOCOL_VERSION);
System.exit(0);
}
boolean debug = cmd.hasOption("debug");
boolean verbose = cmd.hasOption("verbose");
String projectRoot = cmd.getOptionValue("projectRoot", ".");
boolean contents = cmd.hasOption("contents");
String outFile = cmd.getOptionValue("out");
boolean stdout = cmd.hasOption("stdout");
if (stdout && (verbose || debug)) {
System.err.println("debug and verbose options cannot be enabled with -stdout");
System.exit(1);
}
return new Arguments(projectRoot, contents, outFile, stdout);
}
private static Options createOptions() {
Options options = new Options();
options.addOption(new Option(
"help", false,
"Show help."
));
options.addOption(new Option(
"version", false,
"Show version."
));
options.addOption(new Option(
"debug", false,
"Display debug information."
));
options.addOption(new Option(
"verbose", false,
"Display verbose information."
));
options.addOption(new Option(
"projectRoot", true,
"Specifies the project root. Defaults to the current working directory."
));
options.addOption(new Option(
"contents", false,
"File contents will be embedded into the dump."
));
options.addOption(new Option(
"out", true,
"The output file the dump is save to."
));
options.addOption(new Option(
"stdout", false,
"Writes the dump to stdout."
));
options.addOption(new Option(
"stdout", false,
"Writes the dump to stdout."
));
return options;
}
}