2828 help = sn (
2929 args = ['-h' , '--help' ], action = 'help' ),
3030 debug = sn (
31- args = ['--debug' ], action = 'store_true' )
31+ args = ['--debug' ], nargs = '?' , const = True )
3232)
3333
3434def load (cli , caller_file ):
3535
36+ # Init debug target
37+ if '--debug' in sys .argv :
38+ debug_arg_idx = sys .argv .index ('--debug' )
39+ if len (sys .argv ) > debug_arg_idx + 1 and not sys .argv [debug_arg_idx + 1 ].startswith ('-' ):
40+ cli .debug_key = sys .argv [debug_arg_idx + 1 ]
41+
3642 # Assign help tips from cli.msgs
3743 for ctrl_key , ctrl in vars (controls ).items ():
3844 if not hasattr (ctrl , 'help' ) : ctrl .help = getattr (cli .msgs , f'help_{ ctrl_key .upper ()} ' )
@@ -44,7 +50,8 @@ def load(cli, caller_file):
4450 else caller_path .parent .parent )
4551 possible_config_filenames = [
4652 f'{ prefix } { name } .config.json{ suffix } '
47- for prefix in ['.' , '' ] for name in [cli .short_name , cli .name ] for suffix in ['5' , '' , 'c' ]
53+ for prefix in ['.' , '' ] for name in [cli .short_name , cli .name ]
54+ for suffix in ['5' , '' , 'c' ]
4855 ]
4956 for filename in possible_config_filenames :
5057 config_path = Path (cli .project_root ) / filename
@@ -53,7 +60,10 @@ def load(cli, caller_file):
5360 cli .config = data .sns .from_dict (data .json .read (cli .config_filepath ))
5461 cli .config_filename = filename
5562 break
56- log .debug (f'Config file loaded!\n { log .colors .gry } { cli .config } ' if cli .config_filepath else 'No config file found.' )
63+ if hasattr (cli , 'config_filename' ):
64+ log .debug ('Config file loaded!\n {}' , cli )
65+ else :
66+ log .debug ('No config file found.' )
5767
5868 # Parse CLI args
5969 argp = argparse .ArgumentParser (description = cli .description , add_help = False )
@@ -70,7 +80,7 @@ def load(cli, caller_file):
7080 for key , val in vars (parsed_args ).items (): # apply parsed_args to cli.config
7181 if not getattr (cli .config , key , '' ):
7282 setattr (cli .config , key , val )
73- log .debug (f 'Args parsed!\n { log . colors . gry } { cli . config } ' )
83+ log .debug ('Args parsed!\n {}' , cli )
7484
7585 # Init all cli.config vals
7686 for name , ctrl in vars (controls ).items ():
@@ -80,4 +90,5 @@ def load(cli, caller_file):
8090 if val is None and hasattr (ctrl , 'default_val' ):
8191 val = ctrl .default_val
8292 setattr (cli .config , name , val )
83- log .debug (f'All cli.config vals set!\n { log .colors .gry } { cli .config } ' )
93+ log .debug ('All cli.config vals set!\n {}' , cli )
94+
0 commit comments