Skip to content

Commit f5619a0

Browse files
committed
fix: remove command arg reference breaking tests
1 parent bc361f6 commit f5619a0

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

cve_bin_tool/cli.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,6 @@ def main(argv=None):
173173
default="",
174174
)
175175

176-
# Add command argument before directory to ensure proper parsing order
177-
parser.add_argument(
178-
"command",
179-
nargs="?",
180-
choices=["vex-validate"],
181-
help="Command to run: vex-validate to validate VEX files",
182-
)
183-
184176
input_group = parser.add_argument_group("Input")
185177
input_group.add_argument(
186178
"directory", help="directory to scan", nargs="?", default=""
@@ -583,27 +575,27 @@ def main(argv=None):
583575
)
584576

585577
with ErrorHandler(mode=ErrorMode.NoTrace):
586-
raw_args = parser.parse_args(argv[1:])
587-
args = {key: value for key, value in vars(raw_args).items() if value}
588-
defaults = {key: parser.get_default(key) for key in vars(raw_args)}
589-
590-
# Handle vex-validate command early
591-
if raw_args.command == "vex-validate":
592-
if not raw_args.vex_file_to_validate and not raw_args.directory:
593-
parser.error(
594-
"vex-validate command requires either --vex-file-to-validate or a VEX file path as directory argument"
595-
)
578+
# Check if this is a vex-validate command first
579+
if len(argv) >= 2 and argv[1] == "vex-validate":
580+
# For vex-validate, parse known args to avoid issues with extra arguments
581+
raw_args, unknown_args = parser.parse_known_args(argv[1:])
582+
# The VEX file should be the first unknown argument
583+
if unknown_args:
584+
vex_file_path = unknown_args[0]
585+
else:
586+
parser.error("vex-validate command requires a VEX file path")
596587

597-
# Use directory as file path if vex_file_to_validate not provided
598-
vex_file_path = raw_args.vex_file_to_validate or raw_args.directory
588+
# Import and run validation immediately
589+
from cve_bin_tool.vex_manager.validate import validate_vex_file
599590

600-
# Import and run validation locally to avoid scope issues
601-
from cve_bin_tool.vex_manager.validate import validate_vex_file
591+
exit_code = validate_vex_file(vex_file_path, logger=None, offline=False)
592+
return exit_code
593+
else:
594+
# Normal parsing for all other commands
595+
raw_args = parser.parse_args(argv[1:])
602596

603-
exit_code = validate_vex_file(
604-
vex_file_path, logger=None, offline=args.get("offline", False)
605-
)
606-
return exit_code
597+
args = {key: value for key, value in vars(raw_args).items() if value}
598+
defaults = {key: parser.get_default(key) for key in vars(raw_args)}
607599

608600
configs = {}
609601
if args.get("config"):
@@ -774,8 +766,8 @@ def main(argv=None):
774766

775767
return 0
776768

777-
# Handle vex-validate command
778-
if args.get("command") == "vex-validate":
769+
# Handle vex-validate command (this should not be reached due to early return)
770+
if args.get("directory") == "vex-validate":
779771
from cve_bin_tool.vex_manager.validate import validate_vex_file
780772

781773
# Determine VEX file path
@@ -1020,7 +1012,6 @@ def main(argv=None):
10201012
and not args["merge"]
10211013
and not args["sbom_file"]
10221014
and not args["vex_file"]
1023-
and not raw_args.command
10241015
):
10251016
parser.print_usage()
10261017
with ErrorHandler(logger=LOGGER, mode=ErrorMode.NoTrace):

0 commit comments

Comments
 (0)