diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-04-27 15:41:06 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-04-27 15:41:06 -0400 |
commit | 223f8c55df0e3b520f53adcf07d51498d4263f7c (patch) | |
tree | 77866be585e3fda8f646dd90be6b701b4f2461c1 | |
parent | bdd831681d4b9d4202b15157c801a988ccec33df (diff) | |
download | cmd2-git-silence_startup_script.tar.gz |
Renamed silent_startup_script to silence_startup_script for claritysilence_startup_script
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | cmd2/cmd2.py | 8 | ||||
-rw-r--r-- | docs/features/startup_commands.rst | 4 | ||||
-rwxr-xr-x | tests/test_cmd2.py | 8 |
4 files changed, 11 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 461e48ee..11992122 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * Removed `--silent` flag from `alias/macro create` since startup scripts can be run silently. * Removed `--with_silent` flag from `alias/macro list` since startup scripts can be run silently. * Removed `with_argparser_and_unknown_args` since it was deprecated in 1.3.0. + * Renamed `silent_startup_script` to `silence_startup_script` for clarity. * Replaced `cmd2.Cmd.completion_header` with `cmd2.Cmd.formatted_completions`. See Enhancements for description of this new class member. * Settables now have new initialization parameters. It is now a required parameter to supply the reference to the diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 6702d1a7..e5dcca83 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -219,7 +219,7 @@ class Cmd(cmd.Cmd): persistent_history_file: str = '', persistent_history_length: int = 1000, startup_script: str = '', - silent_startup_script: bool = False, + silence_startup_script: bool = False, include_py: bool = False, include_ipy: bool = False, allow_cli_args: bool = True, @@ -241,8 +241,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 silence_startup_script: if ``True``, then the startup script's output will be + suppressed. Anything written to stderr will still display. :param include_py: should the "py" command be included for an embedded Python shell :param include_ipy: 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 @@ -398,7 +398,7 @@ class Cmd(cmd.Cmd): startup_script = os.path.abspath(os.path.expanduser(startup_script)) if os.path.exists(startup_script): script_cmd = f"run_script {utils.quote_string(startup_script)}" - if silent_startup_script: + if silence_startup_script: script_cmd += f" {constants.REDIRECTION_OUTPUT} {os.devnull}" self._startup_commands.append(script_cmd) diff --git a/docs/features/startup_commands.rst b/docs/features/startup_commands.rst index f105054b..951e7fff 100644 --- a/docs/features/startup_commands.rst +++ b/docs/features/startup_commands.rst @@ -65,10 +65,10 @@ This text file should contain a :ref:`Command Script <features/scripting:Command Scripts>`. See the AliasStartup_ example for a demonstration. -You can silence a startup script's output by setting ``silent_startup_script`` +You can silence a startup script's output by setting ``silence_startup_script`` to True:: - cmd2.Cmd.__init__(self, startup_script='.cmd2rc', silent_startup_script=True) + cmd2.Cmd.__init__(self, startup_script='.cmd2rc', silence_startup_script=True) Anything written to stderr will still print. Additionally, a startup script cannot be silenced if ``allow_redirection`` is False since silencing works diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index fb4c9d76..b09141c9 100755 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -2667,17 +2667,17 @@ def test_disabled_message_command_name(disable_commands_app): assert err[0].startswith('has_helper_funcs is currently disabled') -@pytest.mark.parametrize('silent_startup_script', [True, False]) -def test_startup_script(request, capsys, silent_startup_script): +@pytest.mark.parametrize('silence_startup_script', [True, False]) +def test_startup_script(request, capsys, silence_startup_script): test_dir = os.path.dirname(request.module.__file__) startup_script = os.path.join(test_dir, '.cmd2rc') - app = cmd2.Cmd(allow_cli_args=False, startup_script=startup_script, silent_startup_script=silent_startup_script) + app = cmd2.Cmd(allow_cli_args=False, startup_script=startup_script, silence_startup_script=silence_startup_script) assert len(app._startup_commands) == 1 app._startup_commands.append('quit') app.cmdloop() out, err = capsys.readouterr() - if silent_startup_script: + if silence_startup_script: assert not out else: assert out |