Skip to content

Commit 27cd721

Browse files
authored
fix: gen-build-spec maven/gradle cli parsers failed to parse valid command lines with intermixed positional args and options (#1212)
Signed-off-by: Nicholas Allen <[email protected]>
1 parent cc14e57 commit 27cd721

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/macaron/build_spec_generator/cli_command_parser/gradle_cli_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def parse(self, cmd_list: list[str]) -> GradleCLICommand:
534534
# TODO: because our parser is not completed for all cases, should we be more relaxed and use
535535
# parse_unknown_options?
536536
try:
537-
parsed_opts = self.arg_parser.parse_args(options)
537+
parsed_opts = self.arg_parser.parse_intermixed_args(options)
538538
except argparse.ArgumentError as error:
539539
raise CommandLineParseError(f"Failed to parse {' '.join(options)}.") from error
540540
# Even though we have set `exit_on_error`, argparse still exits unexpectedly in some

src/macaron/build_spec_generator/cli_command_parser/maven_cli_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def parse(self, cmd_list: list[str]) -> "MavenCLICommand":
436436
# TODO: because our parser is not completed for all cases, should we be more relaxed and use
437437
# parse_unknown_options?
438438
try:
439-
parsed_opts = self.arg_parser.parse_args(options)
439+
parsed_opts = self.arg_parser.parse_intermixed_args(options)
440440
except argparse.ArgumentError as error:
441441
raise CommandLineParseError(f"Failed to parse command {' '.join(options)}.") from error
442442
# Even though we have set `exit_on_error`, argparse still exits unexpectedly in some

tests/build_spec_generator/cli_command_parser/test_gradle_cli_command.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
"gradlew clean build -x test -x boo",
3939
id="test_excluded_tasks",
4040
),
41+
pytest.param(
42+
"gradlew clean -x test -x boo build",
43+
"gradlew clean build -x test -x boo",
44+
id="test_intermixed_args",
45+
),
4146
],
4247
)
4348
def test_comparing_gradle_cli_command_equal(

tests/build_spec_generator/cli_command_parser/test_maven_cli_command.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
"mvn clean package -Dmaven.skip.test",
2828
id="test_default_value_for_system_property",
2929
),
30+
pytest.param(
31+
"mvn clean package -Dmaven.skip.test=true",
32+
"mvn clean -Dmaven.skip.test=true package",
33+
id="test_intermixed_args",
34+
),
3035
],
3136
)
3237
def test_comparing_maven_cli_command_equal(

0 commit comments

Comments
 (0)