@@ -173,14 +173,6 @@ def main(argv=None):
173
173
default = "" ,
174
174
)
175
175
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
-
184
176
input_group = parser .add_argument_group ("Input" )
185
177
input_group .add_argument (
186
178
"directory" , help = "directory to scan" , nargs = "?" , default = ""
@@ -583,27 +575,27 @@ def main(argv=None):
583
575
)
584
576
585
577
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" )
596
587
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
599
590
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 :])
602
596
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 )}
607
599
608
600
configs = {}
609
601
if args .get ("config" ):
@@ -774,8 +766,8 @@ def main(argv=None):
774
766
775
767
return 0
776
768
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" :
779
771
from cve_bin_tool .vex_manager .validate import validate_vex_file
780
772
781
773
# Determine VEX file path
@@ -1020,7 +1012,6 @@ def main(argv=None):
1020
1012
and not args ["merge" ]
1021
1013
and not args ["sbom_file" ]
1022
1014
and not args ["vex_file" ]
1023
- and not raw_args .command
1024
1015
):
1025
1016
parser .print_usage ()
1026
1017
with ErrorHandler (logger = LOGGER , mode = ErrorMode .NoTrace ):
0 commit comments