-
Notifications
You must be signed in to change notification settings - Fork 418
zzz 961 initial values for arggroups
Remko Popma edited this page Apr 20, 2020
·
1 revision
Index: src/test/java/picocli/ArgGroupTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/test/java/picocli/ArgGroupTest.java (date 1587356173923)
+++ src/test/java/picocli/ArgGroupTest.java (date 1587356173923)
@@ -2366,6 +2366,9 @@
@Option(names = "--l1b", required = true)
private String l1b;
+ @Option(names = "--l1c")
+ private String l1c = "111";
+
@ArgGroup(exclusive = false, multiplicity = "1")
private Level2Argument level2;
}
@@ -2373,9 +2376,13 @@
static class Level2Argument {
@Option(names = "--l2a", required = true, defaultValue = "l2a")
private String l2a;
+
@Option(names = "--l2b", required = true)
private String l2b;
+ @Option(names = "--l2c")
+ private String l2c = "222";
+
@ArgGroup(exclusive = false, multiplicity = "1")
private Level3Argument level3;
}
@@ -2386,6 +2393,9 @@
@Option(names = { "--l3b"}, required = true, defaultValue = "l3b")
private String l3b;
+
+ @Option(names = "--l3c")
+ private String l3c = "333";
}
@Command(name = "arg-group-test", subcommands = {CreateCommand.class, CommandLine.HelpCommand.class})
@@ -2395,8 +2405,11 @@
@Command(name = "create", helpCommand = true)
public static class CreateCommand implements Runnable {
- @Option(names = "--l0", required = true, defaultValue = "l0")
- private String l0;
+ @Option(names = "--l0a", required = true, defaultValue = "l0")
+ private String l0a;
+
+ @Option(names = "--l0b")
+ private String l0b = "000";
@ArgGroup(exclusive = false, multiplicity = "0..1")
private Level1Argument level1 = new Level1Argument();
@@ -2405,15 +2418,27 @@
}
}
+ @Test
+ public void testRequiredOptionsNotMandatoryIfInitialValueIsSpecified() {
+ CommandLine cmd = new CommandLine(new Issue746.Level3Argument());
+ cmd.parseArgs("--l3a=L3A");
+ Issue746.Level3Argument bean = cmd.getCommand();
+ assertEquals("L3A", bean.l3a);
+ assertEquals("l3b", bean.l3b);
+ assertEquals("333", bean.l3c);
+ }
+
@Test
// https://github.com/remkop/picocli/issues/746
public void testIssue746DefaultValueWithNestedArgGroups() {
Issue746.CreateCommand bean = new Issue746.CreateCommand();
CommandLine cmd = new CommandLine(bean);
cmd.parseArgs();
- assertEquals("l0", bean.l0);
+ assertEquals("l0", bean.l0a);
+ assertEquals("000", bean.l0b);
assertEquals("l1a", bean.level1.l1a);
assertNull(bean.level1.l1b);
+ assertEquals("111", bean.level1.l1c);
assertNull(bean.level1.level2);
}
@@ -2421,8 +2446,9 @@
// https://github.com/remkop/picocli/issues/746
public void testIssue746ArgGroupWithDefaultValuesSynopsis() {
String expected = String.format("" +
- "create [[--l1a=<l1a>] --l1b=<l1b> ([--l2a=<l2a>] --l2b=<l2b> (--l3a=<l3a>%n" +
- " [--l3b=<l3b>]))] [--l0=<l0>]%n");
+ "create [[--l1a=<l1a>] --l1b=<l1b> [--l1c=<l1c>] ([--l2a=<l2a>] --l2b=<l2b>%n" +
+ " [--l2c=<l2c>] (--l3a=<l3a> [--l3b=<l3b>] [--l3c=<l3c>]))] [--l0a=<l0a>]%n" +
+ " [--l0b=<l0b>]%n");
CommandLine cmd = new CommandLine(new Issue746.CreateCommand());
Help help = new Help(cmd.getCommandSpec(), Help.defaultColorScheme(Help.Ansi.OFF));
@@ -2434,20 +2460,25 @@
@Test
// https://github.com/remkop/picocli/issues/746
public void testIssue746ArgGroupWithDefaultValuesParsing() {
+ //System.setProperty("picocli.trace", "DEBUG");
Issue746.CreateCommand bean = new Issue746.CreateCommand();
CommandLine cmd = new CommandLine(bean);
cmd.parseArgs("--l1b=L1B --l2b=L2B --l3a=L3A".split(" "));
- assertEquals("default value", "l0", bean.l0);
+ assertEquals("default value", "l0", bean.l0a);
+ assertEquals("default value", "000", bean.l0b);
assertNotNull(bean.level1);
assertEquals("default value", "l1a", bean.level1.l1a);
assertEquals("specified value", "L1B", bean.level1.l1b);
+ assertEquals("initial value", "111", bean.level1.l1c);
assertNotNull(bean.level1.level2);
assertEquals("default value", "l2a", bean.level1.level2.l2a);
assertEquals("specified value", "L2B", bean.level1.level2.l2b);
+ assertEquals("initial value", "222", bean.level1.level2.l2c);
assertNotNull(bean.level1.level2.level3);
assertEquals("default value", "l3b", bean.level1.level2.level3.l3b);
assertEquals("specified value", "L3A", bean.level1.level2.level3.l3a);
+ assertEquals("initial value", "333", bean.level1.level2.level3.l3c);
}
@Command(name = "Issue742")