@@ -566,6 +566,15 @@ def run_suite(args, data, skip_suite):
566566
567567 return skip , err
568568
569+ def get_first_existing_file (list , name ):
570+ for f in list :
571+ if os .path .exists (os .path .expanduser (f )):
572+ return f
573+ vcprint (pcolor .faint , f"({ name } not found: { f } )" )
574+
575+ print ("error, can't find any {name} to use" )
576+ sys .exit (1 )
577+
569578def parse_proj_config (root_path , args ):
570579 files = [
571580 os .path .join (root_path , '..' , '9pm-proj.yaml' ),
@@ -575,21 +584,12 @@ def parse_proj_config(root_path, args):
575584 if "NINEPM_PROJ_CONFIG" in os .environ :
576585 files .insert (0 , os .environ ["NINEPM_PROJ_CONFIG" ])
577586
578- path = next ((os .path .expanduser (f ) for f in files if os .path .exists (os .path .expanduser (f ))), None )
579-
580587 if args .proj :
581- if not os .path .exists (args .proj ):
582- print (f"error, config file \" { args .proj } \" not found." )
583- sys .exit (1 )
588+ files .insert (0 , args .proj )
584589
585- path = args .proj
586-
587- if path :
588- vcprint (pcolor .faint , f"Using project config: { path } " )
589- os .environ ["NINEPM_PROJ_CONFIG" ] = path
590- else :
591- print ("error, can't find any 9pm project config" )
592- sys .exit (1 )
590+ path = get_first_existing_file (files , "Project Config" )
591+ vcprint (pcolor .faint , f"Using project config: { path } " )
592+ os .environ ["NINEPM_PROJ_CONFIG" ] = path
593593
594594 try :
595595 with open (path , 'r' ) as f :
@@ -616,13 +616,9 @@ def parse_rc(root_path, args):
616616 os .path .join ("~/.9pm.rc" ),
617617 os .path .join (root_path , 'etc' , '9pm.rc' )
618618 ]
619- path = next ((os .path .expanduser (f ) for f in files if os .path .exists (os .path .expanduser (f ))), None )
620619
621- if path :
622- vcprint (pcolor .faint , f"Using RC: { path } " )
623- else :
624- print ("error, can't find any 9pm.rc file" )
625- sys .exit (1 )
620+ path = get_first_existing_file (files , "Running Config" )
621+ vcprint (pcolor .faint , f"Using RC: { path } " )
626622
627623 try :
628624 with open (path , 'r' ) as f :
0 commit comments