@@ -457,6 +457,8 @@ def stepOrIndex(s):
457457 opt .overWrite = eval (opt .overWrite )
458458 if opt .interactive :
459459 import cmd
460+ from colorama import Fore , Style
461+ from os import isatty
460462
461463 class TheMatrix (cmd .Cmd ):
462464 intro = "Welcome to the Matrix (? for help)"
@@ -486,6 +488,12 @@ def do_exit(self, arg):
486488 def default (self , inp ):
487489 if inp == 'x' or inp == 'q' :
488490 return self .do_exit (inp )
491+ else :
492+ is_pipe = not isatty (sys .stdin .fileno ())
493+ print (Fore .RED + "Error: " + Fore .RESET + "unrecognized command." )
494+ # Quit only if given a piped command.
495+ if is_pipe :
496+ sys .exit (1 )
489497
490498 def help_predefined (self ):
491499 print ("\n " .join (["predefined [predef1 [...]]\n " ,
@@ -509,7 +517,7 @@ def do_predefined(self, arg):
509517 else :
510518 print ("Unknown Set: %s" % w )
511519 else :
512- print (predefinedSet .keys ())
520+ print ("[ " + Fore . RED + ", " . join ([ str ( k ) for k in predefinedSet .keys ()]) + Fore . RESET + " ]" )
513521
514522 def help_showWorkflow (self ):
515523 print ("\n " .join (["showWorkflow [workflow1 [...]]\n " ,
@@ -526,17 +534,18 @@ def do_showWorkflow(self, arg):
526534 if arg == '' :
527535 print ("Available workflows:" )
528536 for k in self .matrices_ .keys ():
529- print (k )
537+ print (Fore .RED + Style .BRIGHT + k )
538+ print (Style .RESET_ALL )
530539 else :
531540 selected = arg .split ()
532541 for k in selected :
533542 if k not in self .matrices_ .keys ():
534543 print ("Unknown workflow %s: skipping" % k )
535544 else :
536545 for wfl in self .matrices_ [k ].workFlows :
537- wfName , stepNames = wfl . nameId . split ( '+' , 1 )
538- print ( "%s %s %s" % ( wfl .numId , wfName , stepNames ))
539- print ("%s contains %d workflows" % (k , len (self .matrices_ [k ].workFlows )))
546+ print ( "%s %s" % ( Fore . BLUE + str ( wfl . numId ) + Fore . RESET ,
547+ Fore . GREEN + wfl .nameId + Fore . RESET ))
548+ print ("%s contains %d workflows" % (Fore . RED + k + Fore . RESET , len (self .matrices_ [k ].workFlows )))
540549
541550 def help_searchInWorkflow (self ):
542551 print ("\n " .join (["searchInWorkflow wfl_name search_regexp\n " ,
@@ -566,11 +575,12 @@ def do_searchInWorkflow(self, arg):
566575 return
567576 counter = 0
568577 for wfl in self .matrices_ [args [0 ]].workFlows :
569- wfName , stepNames = wfl .nameId .split ('+' ,1 )
570- if re .match (pattern , wfName ) or re .match (pattern , stepNames ):
571- print ("%s %s %s" % (wfl .numId , wfName , stepNames ))
572- counter += 1
573- print ("Found %d compatible workflows inside %s" % (counter , args [0 ]))
578+ if re .match (pattern , wfl .nameId ):
579+ print ("%s %s" % (Fore .BLUE + str (wfl .numId ) + Fore .RESET ,
580+ Fore .GREEN + wfl .nameId + Fore .RESET ))
581+ counter += 1
582+ print ("Found %s compatible workflows inside %s" % (Fore .RED + str (counter ) + Fore .RESET ,
583+ Fore .YELLOW + str (args [0 ])) + Fore .RESET )
574584
575585 def help_search (self ):
576586 print ("\n " .join (["search search_regexp\n " ,
@@ -595,19 +605,19 @@ def do_dumpWorkflowId(self, arg):
595605 print ("dumpWorkflowId [wfl-id1 [...]]" )
596606 return
597607
598- fmt = "[%d ]: %s\n "
608+ fmt = "[%s ]: %s\n "
599609 maxLen = 100
600610 for wflid in wflids :
601611 dump = True
602612 for key , mrd in self .matrices_ .items ():
603613 for wfl in mrd .workFlows :
604614 if wfl .numId == float (wflid ):
605- wfName , stepNames = wfl .nameId .split ('+' ,1 )
606615 if dump :
607616 dump = False
608- print (wfl .numId , stepNames )
617+ print (Fore . GREEN + str ( wfl .numId ) + Fore . RESET + " " + Fore . YELLOW + wfl . nameId + Fore . RESET )
609618 for i ,s in enumerate (wfl .cmds ):
610- print (fmt % (i + 1 , (str (s )+ ' ' )))
619+ print (fmt % (Fore .RED + str (i + 1 ) + Fore .RESET ,
620+ (str (s )+ ' ' )))
611621 print ("\n Workflow found in %s." % key )
612622 else :
613623 print ("Workflow also found in %s." % key )
0 commit comments