diff --git a/src/triton_cli/parser.py b/src/triton_cli/parser.py index 077a1ce..e1d1cd7 100755 --- a/src/triton_cli/parser.py +++ b/src/triton_cli/parser.py @@ -444,9 +444,10 @@ def parse_args(argv=None): argv_ = argv if argv is not None else sys.argv[1:] # Add special argparse handling for passthrough to genai-perf CLI - if argv_[0] == "profile": + if len(argv_) > 1 and argv_[0] == "profile": args, unknown_args = parser.parse_known_args(argv_) args = add_unknown_args_to_args(args, unknown_args) else: args = parser.parse_args(argv_) + return args diff --git a/tests/test_cli.py b/tests/test_cli.py index 2883e70..78abc37 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -49,6 +49,17 @@ class TestRepo: + def test_noargs(self): + # Test that running 'triton' with no args will fail with a parsing error + # NOTE: pytest needs to be run with `--capture=sys` to read the output, + # so just assert the error code and exception type for now. + args = [] + with pytest.raises(SystemExit) as excinfo: + TritonCommands._run_and_capture_stdout(args) + + # argparse returns code 2 for error / missing arguments + assert excinfo.value.code == 2 + @pytest.mark.parametrize("repo", TEST_REPOS) def test_clear(self, repo): TritonCommands._clear(repo)