Skip to content

Commit 5100b5d

Browse files
authored
Fix for issue with multiple -- in command line
Differential Revision: D56317273 Pull Request resolved: #888
1 parent b3d3d39 commit 5100b5d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

torchx/cli/cmd_run.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ def _parse_component_name_and_args(
8686
component_args = args[1:]
8787

8888
# Error if there are repeated command line arguments
89-
all_options = [x for x in component_args if x.startswith("-")]
89+
all_options = [
90+
x
91+
for x in component_args
92+
if x.startswith("-") and x.strip() != "-" and x.strip() != "--"
93+
]
9094
arg_count = Counter(all_options)
9195
duplicates = [arg for arg, count in arg_count.items() if count > 1]
9296
if len(duplicates) > 0:

torchx/cli/test/cmd_run_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,27 @@ def test_parse_component_name_and_args_no_default(self) -> None:
230230
_parse_component_name_and_args(["utils.echo", "--msg", "hello"], sp),
231231
)
232232

233+
self.assertEqual(
234+
("utils.echo", ["--msg", "hello", "--", "--"]),
235+
_parse_component_name_and_args(
236+
["utils.echo", "--msg", "hello", "--", "--"], sp
237+
),
238+
)
239+
240+
self.assertEqual(
241+
("utils.echo", ["--msg", "hello", "-", "-"]),
242+
_parse_component_name_and_args(
243+
["utils.echo", "--msg", "hello", "-", "-"], sp
244+
),
245+
)
246+
247+
self.assertEqual(
248+
("utils.echo", ["--msg", "hello", "- ", "- "]),
249+
_parse_component_name_and_args(
250+
["utils.echo", "--msg", "hello", "- ", "- "], sp
251+
),
252+
)
253+
233254
with self.assertRaises(SystemExit):
234255
_parse_component_name_and_args(["--"], sp)
235256

@@ -245,6 +266,11 @@ def test_parse_component_name_and_args_no_default(self) -> None:
245266
with self.assertRaises(SystemExit):
246267
_parse_component_name_and_args(["--msg", "hello", "--msg", "repeate"], sp)
247268

269+
with self.assertRaises(SystemExit):
270+
_parse_component_name_and_args(
271+
["--msg ", "hello", "--msg ", "repeate"], sp
272+
)
273+
248274
def test_parse_component_name_and_args_with_default(self) -> None:
249275
sp = argparse.ArgumentParser(prog="test")
250276
dirs = [str(self.tmpdir)]

0 commit comments

Comments
 (0)