-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
TranslationTutorialMain.java
49 lines (38 loc) · 1.43 KB
/
TranslationTutorialMain.java
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
package de.tototec.cmdoption;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class TranslationTutorialMain {
public static class Config {
@CmdOption(names = { "--help", "-h" }, description = "Show this help.", isHelp = true)
public boolean help;
@CmdOption(names = { "--verbose", "-v" }, description = "Be more verbose.")
private boolean verbose;
@CmdOption(names = { "--options", "-o" }, args = { "name",
"value" }, maxCount = -1, description = "Additional options when processing names.")
private final Map<String, String> options = new LinkedHashMap<String, String>();
@CmdOption(args = { "file" }, description = "Names to process.", minCount = 1, maxCount = -1)
private final List<String> names = new LinkedList<String>();
}
public static void main(final String[] args) {
final Config config = new Config();
final CmdlineParser cp = new CmdlineParser(config);
cp.setDebugMode(true);
cp.setResourceBundle(TranslationTutorialMain.class.getName() + "_Messages",
TranslationTutorialMain.class.getClassLoader());
cp.setProgramName("myprogram");
cp.setAboutLine("Example names processor v1.0");
try {
cp.parse(args);
} catch (final CmdlineParserException e) {
System.err.println("Error: " + e.getLocalizedMessage() + "\nRun myprogram --help for help.");
System.exit(1);
}
if (config.help) {
cp.usage();
return;
}
// ...
}
}