@@ -472,10 +472,23 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
472472 self ._startup_commands .append ("load '{}'" .format (startup_script ))
473473
474474 # Transcript files to run instead of interactive command loop
475- self ._transcript_files = transcript_files
475+ self ._transcript_files = None
476476
477- # Should commands at invocation and -t/--test transcript test running be allowed
478- self ._allow_cli_args = allow_cli_args
477+ # Check for command line args
478+ if allow_cli_args :
479+ parser = argparse .ArgumentParser ()
480+ parser .add_argument ('-t' , '--test' , action = "store_true" ,
481+ help = 'Test against transcript(s) in FILE (wildcards OK)' )
482+ callopts , callargs = parser .parse_known_args ()
483+
484+ # If transcript testing was called for, use other arguments as transcript files
485+ if callopts .test :
486+ self ._transcript_files = callargs
487+ # If commands were supplied at invocation, then add them to the command queue
488+ elif callargs :
489+ self ._startup_commands .extend (callargs )
490+ elif transcript_files :
491+ self ._transcript_files = transcript_files
479492
480493 # The default key for sorting tab completion matches. This only applies when the matches are not
481494 # already marked as sorted by setting self.matches_sorted to True. Its default value performs a
@@ -4013,20 +4026,6 @@ def cmdloop(self, intro: Optional[str] = None) -> int:
40134026 original_sigint_handler = signal .getsignal (signal .SIGINT )
40144027 signal .signal (signal .SIGINT , self .sigint_handler )
40154028
4016- # Check for command line args
4017- if self ._allow_cli_args :
4018- parser = argparse .ArgumentParser ()
4019- parser .add_argument ('-t' , '--test' , action = "store_true" ,
4020- help = 'Test against transcript(s) in FILE (wildcards OK)' )
4021- callopts , callargs = parser .parse_known_args ()
4022-
4023- # If transcript testing was called for, use other arguments as transcript files
4024- if callopts .test :
4025- self ._transcript_files = callargs
4026- # If commands were supplied at invocation, then add them to the command queue
4027- elif callargs :
4028- self ._startup_commands .extend (callargs )
4029-
40304029 # Grab terminal lock before the prompt has been drawn by readline
40314030 self .terminal_lock .acquire ()
40324031
0 commit comments