@@ -13,16 +13,16 @@ def emit(self, record):
1313
1414DEFAULT_CONFIG_FILES = ['lightbeam.yaml' , 'lightbeam.yml' ]
1515
16- ALL_COMMANDS = [
17- "validate" ,
18- "send" ,
19- "validate+send" ,
20- "delete" ,
21- "truncate" ,
22- "count" ,
23- "fetch" ,
24- ]
25- command_list = ', ' .join (f"'{ c } '" for c in ALL_COMMANDS )
16+ ALL_COMMANDS = {
17+ "validate" : "validate" ,
18+ "send" : "send" ,
19+ "validate+send" : "validate+send" ,
20+ "delete" : "delete" ,
21+ "truncate" : "truncate" ,
22+ "count" : "count" ,
23+ "fetch" : "fetch" ,
24+ }
25+ command_list = ', ' .join (f"'{ c } '" for c in ALL_COMMANDS . values () )
2626
2727# Set up logging
2828handler = ExitOnExceptionHandler ()
@@ -109,7 +109,18 @@ def main(argv=None):
109109
110110 defaults = { "selector" :"*" , "params" : "" , "older_than" : "" , "newer_than" : "" , "resend_status_codes" : "" , "results_file" : "" }
111111 parser .set_defaults (** defaults )
112- args , remaining_argv = parser .parse_known_args ()
112+ args , unknown_args = parser .parse_known_args ()
113+ if len (unknown_args ) > 0 :
114+ unknown_args_str = ', ' .join (f"`{ c } `" for c in unknown_args )
115+ print (f"unknown arguments { unknown_args_str } passed, use -h flag for help" )
116+ exit (1 )
117+
118+ if args .command not in ALL_COMMANDS .values ():
119+ if args .command is None :
120+ logger .error (f"no command provided. Use one of ({ command_list } ), see -h flag for help" )
121+ else :
122+ logger .error (f"unknown command '{ args .command } ' passed, use -h flag for help" )
123+ exit (1 )
113124
114125 if args .version :
115126 lb_dir = os .path .dirname (os .path .abspath (__file__ ))
@@ -119,9 +130,6 @@ def main(argv=None):
119130 print (f"lightbeam, version { VERSION } " )
120131 exit (0 )
121132
122- if args .command not in ALL_COMMANDS :
123- logger .error (f"Please specify a command to run: { command_list } . (Try the -h flag for help.)" )
124-
125133 if not args .config_file :
126134 for file in DEFAULT_CONFIG_FILES :
127135 test_file = os .path .join ("." , file )
@@ -151,15 +159,15 @@ def main(argv=None):
151159 )
152160 try :
153161 logger .info ("starting..." )
154- if args .command == 'count' : lb .counter .count ()
155- elif args .command == 'fetch' : lb .fetcher .fetch ()
156- elif args .command == 'validate' : lb .validator .validate ()
157- elif args .command == 'send' : lb .sender .send ()
158- elif args .command == 'validate+send' :
162+ if args .command == ALL_COMMANDS [ 'count' ] : lb .counter .count ()
163+ elif args .command == ALL_COMMANDS [ 'fetch' ] : lb .fetcher .fetch ()
164+ elif args .command == ALL_COMMANDS [ 'validate' ] : lb .validator .validate ()
165+ elif args .command == ALL_COMMANDS [ 'send' ] : lb .sender .send ()
166+ elif args .command == ALL_COMMANDS [ 'validate+send' ] :
159167 lb .validator .validate ()
160168 lb .sender .send ()
161- elif args .command == 'delete' : lb .deleter .delete ()
162- elif args .command == 'truncate' : lb .truncator .truncate ()
169+ elif args .command == ALL_COMMANDS [ 'delete' ] : lb .deleter .delete ()
170+ elif args .command == ALL_COMMANDS [ 'truncate' ] : lb .truncator .truncate ()
163171 lb .logger .info ("done!" )
164172 except Exception as e :
165173 logger .exception (e , exc_info = lb .config ["show_stacktrace" ])
0 commit comments