Skip to content

Commit

Permalink
Updated CommandSpec.remove(ArgSpec arg) method to remove the arg from…
Browse files Browse the repository at this point in the history
… args (List<ArgSpec>) and test case corresponding to same.
  • Loading branch information
kaushalkumar authored and remkop committed Sep 15, 2021
1 parent 5a95ec3 commit acc0c8f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6728,6 +6728,7 @@ public CommandSpec remove(ArgSpec arg) {
if (positionalParameters.remove(arg)) {
removed++;
}
args.remove(arg);
if (removed == 0) {
throw new NoSuchElementException(String.valueOf(arg));
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/picocli/ModelCommandSpecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,7 @@ class MyApp {
spec.remove(old);
spec.add(newOpenOption);

assertFalse(spec.args().contains(old));
String expectAfter = String.format("" +
"Usage: <main class>%n");
assertEquals(expectAfter, cmd.getUsageMessage(Ansi.OFF));
Expand All @@ -1410,6 +1411,7 @@ class Positional {
assertEquals(CommandLine.Range.valueOf("1"), second.index());

spec.remove(second);
assertFalse(spec.args().contains(second));
assertEquals(1, spec.positionalParameters().size());
assertSame(first, spec.positionalParameters().get(0));
}
Expand Down

0 comments on commit acc0c8f

Please sign in to comment.