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:
committed by
Stéphane Nicoll
parent
0f707706f1
commit
b4131ce131
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user