summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-01-22 16:13:05 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-01-22 16:13:05 -0500
commitb2c7113bc74c802bc8822dd1f0659339e8147380 (patch)
tree3174c0758dc767fbadcce79c9b4f674d7044bc74
parent45580056485328338899dd65607c6c57d3797f35 (diff)
downloadcmd2-git-b2c7113bc74c802bc8822dd1f0659339e8147380.tar.gz
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.
-rw-r--r--CHANGELOG.md2
-rw-r--r--cmd2/cmd2.py36
-rwxr-xr-xtests/test_cmd2.py14
3 files changed, 8 insertions, 44 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1a534938..da6c5e9b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@
* Moved `basic_complete` from utils into `cmd2.Cmd` class.
* Moved `CompletionError` to exceptions.py
* ``Namespace.__statement__`` has been removed. Use `Namespace.cmd2_statement.get()` instead.
+ * 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.
* Enhancements
* Added support for custom tab completion and up-arrow input history to `cmd2.Cmd2.read_input`.
See [read_input.py](https://github.com/python-cmd2/cmd2/blob/master/examples/read_input.py)
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index b6b63d42..f40dac98 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -2899,9 +2899,6 @@ class Cmd(cmd.Cmd):
" alias create save_results print_results \">\" out.txt\n")
alias_create_parser = DEFAULT_ARGUMENT_PARSER(description=alias_create_description, epilog=alias_create_epilog)
- alias_create_parser.add_argument('-s', '--silent', action='store_true',
- help='do not print message confirming alias was created or\n'
- 'overwritten')
alias_create_parser.add_argument('name', help='name of this alias')
alias_create_parser.add_argument('command', help='what the alias resolves to',
choices_provider=_get_commands_aliases_and_macros_for_completion)
@@ -2936,9 +2933,8 @@ class Cmd(cmd.Cmd):
value += ' ' + ' '.join(args.command_args)
# Set the alias
- if not args.silent:
- result = "overwritten" if args.name in self.aliases else "created"
- self.poutput("Alias '{}' {}".format(args.name, result))
+ result = "overwritten" if args.name in self.aliases else "created"
+ self.poutput("Alias '{}' {}".format(args.name, result))
self.aliases[args.name] = value
@@ -2975,20 +2971,12 @@ class Cmd(cmd.Cmd):
"Without arguments, all aliases will be listed.")
alias_list_parser = DEFAULT_ARGUMENT_PARSER(description=alias_list_description)
- alias_list_parser.add_argument('-w', '--with_silent', action='store_true',
- help="include --silent flag with listed aliases\n"
- "Use this option when saving to a startup script that\n"
- "should silently create aliases.")
alias_list_parser.add_argument('names', nargs=argparse.ZERO_OR_MORE, help='alias(es) to list',
choices_provider=_get_alias_completion_items, descriptive_header='Value')
@as_subcommand_to('alias', 'list', alias_list_parser, help=alias_delete_help)
def _alias_list(self, args: argparse.Namespace) -> None:
"""List some or all aliases as 'alias create' commands"""
- create_cmd = "alias create"
- if args.with_silent:
- create_cmd += " --silent"
-
tokens_to_quote = constants.REDIRECTION_TOKENS
tokens_to_quote.extend(self.statement_parser.terminators)
@@ -3013,7 +3001,7 @@ class Cmd(cmd.Cmd):
if args:
val += ' ' + ' '.join(args)
- self.poutput("{} {} {}".format(create_cmd, name, val))
+ self.poutput("alias create {} {}".format(name, val))
for name in not_found:
self.perror("Alias '{}' not found".format(name))
@@ -3080,9 +3068,6 @@ class Cmd(cmd.Cmd):
" will only complete paths while typing a macro.")
macro_create_parser = DEFAULT_ARGUMENT_PARSER(description=macro_create_description, epilog=macro_create_epilog)
- macro_create_parser.add_argument('-s', '--silent', action='store_true',
- help='do not print message confirming macro was created or\n'
- 'overwritten')
macro_create_parser.add_argument('name', help='name of this macro')
macro_create_parser.add_argument('command', help='what the macro resolves to',
choices_provider=_get_commands_aliases_and_macros_for_completion)
@@ -3164,9 +3149,8 @@ class Cmd(cmd.Cmd):
break
# Set the macro
- if not args.silent:
- result = "overwritten" if args.name in self.macros else "created"
- self.poutput("Macro '{}' {}".format(args.name, result))
+ result = "overwritten" if args.name in self.macros else "created"
+ self.poutput("Macro '{}' {}".format(args.name, result))
self.macros[args.name] = Macro(name=args.name, value=value, minimum_arg_count=max_arg_num, arg_list=arg_list)
@@ -3202,20 +3186,12 @@ class Cmd(cmd.Cmd):
"Without arguments, all macros will be listed.")
macro_list_parser = DEFAULT_ARGUMENT_PARSER(description=macro_list_description)
- macro_list_parser.add_argument('-w', '--with_silent', action='store_true',
- help="include --silent flag with listed macros\n"
- "Use this option when saving to a startup script that\n"
- "should silently create macros.")
macro_list_parser.add_argument('names', nargs=argparse.ZERO_OR_MORE, help='macro(s) to list',
choices_provider=_get_macro_completion_items, descriptive_header='Value')
@as_subcommand_to('macro', 'list', macro_list_parser, help=macro_list_help)
def _macro_list(self, args: argparse.Namespace) -> None:
"""List some or all macros as 'macro create' commands"""
- create_cmd = "macro create"
- if args.with_silent:
- create_cmd += " --silent"
-
tokens_to_quote = constants.REDIRECTION_TOKENS
tokens_to_quote.extend(self.statement_parser.terminators)
@@ -3240,7 +3216,7 @@ class Cmd(cmd.Cmd):
if args:
val += ' ' + ' '.join(args)
- self.poutput("{} {} {}".format(create_cmd, name, val))
+ self.poutput("macro create {} {}".format(name, val))
for name in not_found:
self.perror("Macro '{}' not found".format(name))
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index f9109a23..bba5a43e 100755
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1676,13 +1676,6 @@ def test_alias_create(base_app):
out, err = run_cmd(base_app, 'alias list fake')
assert out == normalize('alias create fake help')
- # Test silent flag
- out, err = run_cmd(base_app, 'alias create --silent fake set')
- assert not out
-
- out, err = run_cmd(base_app, 'alias list --with_silent fake')
- assert out == normalize('alias create --silent fake set')
-
def test_alias_create_with_quoted_tokens(base_app):
"""Demonstrate that quotes in alias value will be preserved"""
create_command = 'alias create fake help ">" "out file.txt" ";"'
@@ -1786,13 +1779,6 @@ def test_macro_create(base_app):
out, err = run_cmd(base_app, 'macro list fake')
assert out == normalize('macro create fake help')
- # Test silent flag
- out, err = run_cmd(base_app, 'macro create --silent fake set')
- assert not out
-
- out, err = run_cmd(base_app, 'macro list --with_silent fake')
- assert out == normalize('macro create --silent fake set')
-
def test_macro_create_with_quoted_tokens(base_app):
"""Demonstrate that quotes in macro value will be preserved"""
create_command = 'macro create fake help ">" "out file.txt" ";"'