Support "--" end of options in SimpleCommandLineArgsParser

Prior to this commit, the `SimpleCommandLineArgsParser` would reject
"--" arguments as invalid. As reported by the community, the POSIX
utility conventions (Guideline 10) state that

> The first -- argument that is not an option-argument should be
> accepted as a delimiter indicating the end of options.
> Any following arguments should be treated as operands, even if they
> begin with the '-' character.

This commit updates `SimpleCommandLineArgsParser` to not reject "--"
arguments and instead to consider remaining arguments as non-optional.

See gh-31513
This commit is contained in:
Brian Clozel
2023-10-27 11:52:45 +02:00
committed by Stéphane Nicoll
parent 0f707706f1
commit b4131ce131
2 changed files with 32 additions and 16 deletions

View File

@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
*
* @author Chris Beams
* @author Sam Brannen
* @author Brian Clozel
*/
class SimpleCommandLineArgsParserTests {
@@ -66,11 +67,6 @@ class SimpleCommandLineArgsParserTests {
assertThat(args.getOptionValues("o3")).isNull();
}
@Test
void withEmptyOptionText() {
assertThatIllegalArgumentException().isThrownBy(() -> parser.parse("--"));
}
@Test
void withEmptyOptionName() {
assertThatIllegalArgumentException().isThrownBy(() -> parser.parse("--=v1"));
@@ -112,4 +108,13 @@ class SimpleCommandLineArgsParserTests {
args.getNonOptionArgs().add("foo"));
}
@Test
void supportsEndOfOptionsDelimiter() {
CommandLineArgs args = parser.parse("--o1=v1", "--", "--o2=v2");
assertThat(args.containsOption("o1")).isTrue();
assertThat(args.containsOption("o2")).isFalse();
assertThat(args.getOptionValues("o1")).containsExactly("v1");
assertThat(args.getNonOptionArgs()).contains("--o2=v2");
}
}