@@ -199,7 +199,7 @@ class Cmd(cmd.Cmd):
199
199
200
200
def __init__ (self , completekey : str = 'tab' , stdin = None , stdout = None , * ,
201
201
persistent_history_file : str = '' , persistent_history_length : int = 1000 ,
202
- startup_script : str = '' , use_ipython : bool = False ,
202
+ startup_script : str = '' , silent_startup_script : bool = False , use_ipython : bool = False ,
203
203
allow_cli_args : bool = True , transcript_files : Optional [List [str ]] = None ,
204
204
allow_redirection : bool = True , multiline_commands : Optional [List [str ]] = None ,
205
205
terminators : Optional [List [str ]] = None , shortcuts : Optional [Dict [str , str ]] = None ,
@@ -215,6 +215,8 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
215
215
:param persistent_history_length: max number of history items to write
216
216
to the persistent history file
217
217
:param startup_script: file path to a script to execute at startup
218
+ :param silent_startup_script: if ``True``, then the startup script's output will be
219
+ suppressed. Anything written to stderr will still display.
218
220
:param use_ipython: should the "ipy" command be included for an embedded IPython shell
219
221
:param allow_cli_args: if ``True``, then :meth:`cmd2.Cmd.__init__` will process command
220
222
line arguments as either commands to be run or, if ``-t`` or
@@ -363,7 +365,10 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
363
365
if startup_script :
364
366
startup_script = os .path .abspath (os .path .expanduser (startup_script ))
365
367
if os .path .exists (startup_script ):
366
- self ._startup_commands .append ("run_script {}" .format (utils .quote_string (startup_script )))
368
+ script_cmd = "run_script {}" .format (utils .quote_string (startup_script ))
369
+ if silent_startup_script :
370
+ script_cmd += "> {}" .format (os .devnull )
371
+ self ._startup_commands .append (script_cmd )
367
372
368
373
# Transcript files to run instead of interactive command loop
369
374
self ._transcript_files = None # type: Optional[List[str]]
0 commit comments