summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2021-01-24 11:07:50 -0500
committerGitHub <noreply@github.com>2021-01-24 11:07:50 -0500
commit44eb9d4e1946a3cc9a10fe85ccb617b6076f627c (patch)
treedf5a6d6b7f9a173eb387e17408750a2ce57b84c2 /cmd2/cmd2.py
parent5f1ea98c1513225c7bf87976ca438410afff2268 (diff)
parentbc01feced61d493ad8a0e3cc3d5e4768e5d214be (diff)
downloadcmd2-git-44eb9d4e1946a3cc9a10fe85ccb617b6076f627c.tar.gz
Merge pull request #1045 from python-cmd2/silent_start
Added option to run startup scripts silently
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 689f81a5..8ad3f7ba 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -199,7 +199,7 @@ class Cmd(cmd.Cmd):
def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
persistent_history_file: str = '', persistent_history_length: int = 1000,
- startup_script: str = '', use_ipython: bool = False,
+ startup_script: str = '', silent_startup_script: bool = False, use_ipython: bool = False,
allow_cli_args: bool = True, transcript_files: Optional[List[str]] = None,
allow_redirection: bool = True, multiline_commands: Optional[List[str]] = None,
terminators: Optional[List[str]] = None, shortcuts: Optional[Dict[str, str]] = None,
@@ -215,6 +215,8 @@ class Cmd(cmd.Cmd):
:param persistent_history_length: max number of history items to write
to the persistent history file
:param startup_script: file path to a script to execute at startup
+ :param silent_startup_script: if ``True``, then the startup script's output will be
+ suppressed. Anything written to stderr will still display.
:param use_ipython: should the "ipy" command be included for an embedded IPython shell
:param allow_cli_args: if ``True``, then :meth:`cmd2.Cmd.__init__` will process command
line arguments as either commands to be run or, if ``-t`` or
@@ -363,7 +365,10 @@ class Cmd(cmd.Cmd):
if startup_script:
startup_script = os.path.abspath(os.path.expanduser(startup_script))
if os.path.exists(startup_script):
- self._startup_commands.append("run_script {}".format(utils.quote_string(startup_script)))
+ script_cmd = "run_script {}".format(utils.quote_string(startup_script))
+ if silent_startup_script:
+ script_cmd += "> {}".format(os.devnull)
+ self._startup_commands.append(script_cmd)
# Transcript files to run instead of interactive command loop
self._transcript_files = None # type: Optional[List[str]]