Skip to content

Commit

Permalink
[#564][#370] Add tests for relative indices for positional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Mar 22, 2020
1 parent 06b1798 commit 2de6807
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -5710,6 +5710,15 @@ public CommandSpec addPositional(PositionalParamSpec positional) {
positional.index = new Range(i, i, index.isVariable(), index.isUnspecified, index.originalValue);
positional.initCapacity();
}
if (positional.scopeType() == ScopeType.INHERIT) {
Set<CommandLine> done = new HashSet<CommandLine>();
for (CommandLine sub : subcommands().values()) {
if (!done.contains(sub)) {
sub.getCommandSpec().addPositional(PositionalParamSpec.builder(positional).build());
done.add(sub);
}
}
}
return this;
}
private CommandSpec addArg(ArgSpec arg) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/picocli/InheritedOptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void testProgrammaticPositionalParamLocalByDefault() {
assertEquals(LOCAL, PositionalParamSpec.builder().build().scopeType());
}

@Ignore("Needs https://github.com/remkop/picocli/issues/564 and https://github.com/remkop/picocli/issues/370")
//@Ignore("Needs https://github.com/remkop/picocli/issues/564 and https://github.com/remkop/picocli/issues/370")
@Test
public void testProgrammaticAddPositionalParamBeforeSub() {
PositionalParamSpec optA = PositionalParamSpec.builder().scopeType(INHERIT).build();
Expand All @@ -226,14 +226,14 @@ public void testProgrammaticAddPositionalParamBeforeSub() {
assertFalse(sub.positionalParameters().isEmpty());
}

@Ignore("Needs https://github.com/remkop/picocli/issues/564 and https://github.com/remkop/picocli/issues/370")
//@Ignore("Needs https://github.com/remkop/picocli/issues/564 and https://github.com/remkop/picocli/issues/370")
@Test
public void testProgrammaticAddPositionalParamAfterSub() {
PositionalParamSpec optA = PositionalParamSpec.builder().scopeType(INHERIT).build();
PositionalParamSpec positional = PositionalParamSpec.builder().scopeType(INHERIT).build();
CommandSpec spec = CommandSpec.create();
CommandSpec sub = CommandSpec.create();
spec.addSubcommand("sub", sub);
spec.add(optA);
spec.add(positional);
assertFalse(spec.positionalParameters().isEmpty());
assertFalse(sub.positionalParameters().isEmpty());
}
Expand Down
13 changes: 4 additions & 9 deletions src/test/java/picocli/InterpolatedModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ static class CommonMixinTwo {
private String commonMixinTwoParam;
}

@Ignore
@Test
// test for https://github.com/remkop/picocli/issues/564
public void testMixinsWithVariableIndex() {
Expand All @@ -379,15 +378,11 @@ class TestCommand {
// ...

String expected = String.format("" +
"Usage: testCommand [COMMON-PARAM-ONE...] [TEST-COMMAND-PARAM...]%n" +
" [COMMON-PARAM-TWO...]%n" +
"Usage: testCommand COMMON-PARAM-ONE TEST-COMMAND-PARAM COMMON-PARAM-TWO%n" +
"Example for issue 564%n" +
" [COMMON-PARAM-ONE...]%n" +
"%n" +
" [TEST-COMMAND-PARAM...]%n" +
"%n" +
" [COMMON-PARAM-TWO...]%n" +
"%n");
" COMMON-PARAM-ONE%n" +
" TEST-COMMAND-PARAM%n" +
" COMMON-PARAM-TWO%n");
String actual = cmd.getUsageMessage();
assertEquals(expected, actual);
}
Expand Down

0 comments on commit 2de6807

Please sign in to comment.