diff --git a/src/macaron/build_spec_generator/cli_command_parser/gradle_cli_parser.py b/src/macaron/build_spec_generator/cli_command_parser/gradle_cli_parser.py index f381c505c..e2b646c91 100644 --- a/src/macaron/build_spec_generator/cli_command_parser/gradle_cli_parser.py +++ b/src/macaron/build_spec_generator/cli_command_parser/gradle_cli_parser.py @@ -534,7 +534,7 @@ def parse(self, cmd_list: list[str]) -> GradleCLICommand: # TODO: because our parser is not completed for all cases, should we be more relaxed and use # parse_unknown_options? try: - parsed_opts = self.arg_parser.parse_args(options) + parsed_opts = self.arg_parser.parse_intermixed_args(options) except argparse.ArgumentError as error: raise CommandLineParseError(f"Failed to parse {' '.join(options)}.") from error # Even though we have set `exit_on_error`, argparse still exits unexpectedly in some diff --git a/src/macaron/build_spec_generator/cli_command_parser/maven_cli_parser.py b/src/macaron/build_spec_generator/cli_command_parser/maven_cli_parser.py index c4877cbdd..62cb66d4f 100644 --- a/src/macaron/build_spec_generator/cli_command_parser/maven_cli_parser.py +++ b/src/macaron/build_spec_generator/cli_command_parser/maven_cli_parser.py @@ -436,7 +436,7 @@ def parse(self, cmd_list: list[str]) -> "MavenCLICommand": # TODO: because our parser is not completed for all cases, should we be more relaxed and use # parse_unknown_options? try: - parsed_opts = self.arg_parser.parse_args(options) + parsed_opts = self.arg_parser.parse_intermixed_args(options) except argparse.ArgumentError as error: raise CommandLineParseError(f"Failed to parse command {' '.join(options)}.") from error # Even though we have set `exit_on_error`, argparse still exits unexpectedly in some diff --git a/tests/build_spec_generator/cli_command_parser/test_gradle_cli_command.py b/tests/build_spec_generator/cli_command_parser/test_gradle_cli_command.py index 6143dc2af..7363fe991 100644 --- a/tests/build_spec_generator/cli_command_parser/test_gradle_cli_command.py +++ b/tests/build_spec_generator/cli_command_parser/test_gradle_cli_command.py @@ -38,6 +38,11 @@ "gradlew clean build -x test -x boo", id="test_excluded_tasks", ), + pytest.param( + "gradlew clean -x test -x boo build", + "gradlew clean build -x test -x boo", + id="test_intermixed_args", + ), ], ) def test_comparing_gradle_cli_command_equal( diff --git a/tests/build_spec_generator/cli_command_parser/test_maven_cli_command.py b/tests/build_spec_generator/cli_command_parser/test_maven_cli_command.py index 36e9c286e..33ad2c276 100644 --- a/tests/build_spec_generator/cli_command_parser/test_maven_cli_command.py +++ b/tests/build_spec_generator/cli_command_parser/test_maven_cli_command.py @@ -27,6 +27,11 @@ "mvn clean package -Dmaven.skip.test", id="test_default_value_for_system_property", ), + pytest.param( + "mvn clean package -Dmaven.skip.test=true", + "mvn clean -Dmaven.skip.test=true package", + id="test_intermixed_args", + ), ], ) def test_comparing_maven_cli_command_equal(