MCPcopy Create free account
hub / github.com/cbeust/jcommander / parseArgs

Method parseArgs

src/test/java/com/beust/jcommander/CmdTest.java:23–47  ·  view source on GitHub ↗
(boolean withDefault, String[] args)

Source from the content-addressed store, hash-verified

21 }
22
23 public String parseArgs(boolean withDefault, String[] args) {
24 JCommander jc = new JCommander();
25 jc.addCommand(new CmdOne());
26 jc.addCommand(new CmdTwo());
27
28 if (withDefault) {
29 // First check if a command was given, when not prepend default
30 // command (--cmd-two")
31 // In version up to 1.23 JCommander throws an Exception in this
32 // line,
33 // which might be incorrect, at least its not reasonable if the
34 // method
35 // is named "WithoutValidation".
36 jc.parseWithoutValidation(args);
37 if (jc.getParsedCommand() == null) {
38 LinkedList<String> newArgs = new LinkedList<>();
39 newArgs.add("--cmd-two");
40 newArgs.addAll(Arrays.asList(args));
41 jc.parse(newArgs.toArray(new String[0]));
42 }
43 } else {
44 jc.parse(args);
45 }
46 return jc.getParsedCommand();
47 }
48
49 @DataProvider
50 public Object[][] testData() {

Callers 3

Calls 4

addCommandMethod · 0.95
getParsedCommandMethod · 0.95
parseMethod · 0.95

Tested by

no test coverage detected