summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-10-02 23:18:09 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-10-02 23:18:09 -0400
commit9c5c3145cceb97d474cbb5b993033d54cc2b6d4b (patch)
treeaf3d3b1a71ae3657dfac74c46402c443fd5ef41c
parent957137a886e76f5b32f62f667673a72a813f8c0d (diff)
downloadcmd2-git-9c5c3145cceb97d474cbb5b993033d54cc2b6d4b.tar.gz
Don't worry about unquoting alias and macro names as they shouldn't be entered this way anyway
-rw-r--r--cmd2/cmd2.py34
-rw-r--r--tests/test_cmd2.py32
2 files changed, 10 insertions, 56 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index fe1f5c02..e75877f3 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -2209,10 +2209,9 @@ class Cmd(cmd.Cmd):
# ----- Alias subcommand functions -----
def alias_create(self, args: argparse.Namespace):
- """ Creates or overwrites an alias """
+ """Create or overwrites an alias"""
# Validate the alias name
- args.name = utils.strip_quotes(args.name)
valid, errmsg = self.statement_parser.is_valid_command(args.name)
if not valid:
self.perror("Invalid alias name: {}".format(errmsg), traceback_war=False)
@@ -2235,17 +2234,14 @@ class Cmd(cmd.Cmd):
self.poutput("Alias '{}' {}".format(args.name, result))
def alias_delete(self, args: argparse.Namespace):
- """ Deletes aliases """
+ """Delete aliases"""
if args.all:
self.aliases.clear()
self.poutput("All aliases deleted")
elif not args.name:
self.do_help('alias delete')
else:
- # Get rid of duplicates and strip quotes since the argparse decorator for do_alias() preserves them
- aliases_to_delete = [utils.strip_quotes(cur_name) for cur_name in utils.remove_duplicates(args.name)]
-
- for cur_name in aliases_to_delete:
+ for cur_name in utils.remove_duplicates(args.name):
if cur_name in self.aliases:
del self.aliases[cur_name]
self.poutput("Alias '{}' deleted".format(cur_name))
@@ -2253,12 +2249,9 @@ class Cmd(cmd.Cmd):
self.perror("Alias '{}' does not exist".format(cur_name), traceback_war=False)
def alias_list(self, args: argparse.Namespace):
- """ Lists some or all aliases """
+ """List some or all aliases"""
if args.name:
- # Get rid of duplicates and strip quotes since the argparse decorator for do_alias() preserves them
- names_to_view = [utils.strip_quotes(cur_name) for cur_name in utils.remove_duplicates(args.name)]
-
- for cur_name in names_to_view:
+ for cur_name in utils.remove_duplicates(args.name):
if cur_name in self.aliases:
self.poutput("alias create {} {}".format(cur_name, self.aliases[cur_name]))
else:
@@ -2344,10 +2337,9 @@ class Cmd(cmd.Cmd):
# ----- Macro subcommand functions -----
def macro_create(self, args: argparse.Namespace):
- """ Creates or overwrites a macro """
+ """Create or overwrites a macro"""
# Validate the macro name
- args.name = utils.strip_quotes(args.name)
valid, errmsg = self.statement_parser.is_valid_command(args.name)
if not valid:
self.perror("Invalid macro name: {}".format(errmsg), traceback_war=False)
@@ -2420,17 +2412,14 @@ class Cmd(cmd.Cmd):
self.poutput("Macro '{}' {}".format(args.name, result))
def macro_delete(self, args: argparse.Namespace):
- """ Deletes macros """
+ """Delete macros"""
if args.all:
self.macros.clear()
self.poutput("All macros deleted")
elif not args.name:
self.do_help('macro delete')
else:
- # Get rid of duplicates and strip quotes since the argparse decorator for do_macro() preserves them
- macros_to_delete = [utils.strip_quotes(cur_name) for cur_name in utils.remove_duplicates(args.name)]
-
- for cur_name in macros_to_delete:
+ for cur_name in utils.remove_duplicates(args.name):
if cur_name in self.macros:
del self.macros[cur_name]
self.poutput("Macro '{}' deleted".format(cur_name))
@@ -2438,12 +2427,9 @@ class Cmd(cmd.Cmd):
self.perror("Macro '{}' does not exist".format(cur_name), traceback_war=False)
def macro_list(self, args: argparse.Namespace):
- """ Lists some or all macros """
+ """List some or all macros"""
if args.name:
- # Get rid of duplicates and strip quotes since the argparse decorator for do_macro() preserves them
- names_to_view = [utils.strip_quotes(cur_name) for cur_name in utils.remove_duplicates(args.name)]
-
- for cur_name in names_to_view:
+ for cur_name in utils.remove_duplicates(args.name):
if cur_name in self.macros:
self.poutput("macro create {} {}".format(cur_name, self.macros[cur_name].value))
else:
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 3d57a105..dd89dd52 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1860,22 +1860,6 @@ def test_alias_create(base_app, capsys):
out = run_cmd(base_app, 'alias list fake')
assert out == normalize('alias create fake pyscript')
-def test_alias_quoted_name(base_app, capsys):
- """Demonstrate that names can be quoted in alias commands because they will be stripped"""
- # Create the alias
- out = run_cmd(base_app, 'alias create "fake" pyscript')
-
- # The quotes on names are stripped
- assert out == normalize("Alias 'fake' created")
-
- # Look up the new alias and quote the name
- out = run_cmd(base_app, 'alias list "fake"')
- assert out == normalize('alias create fake pyscript')
-
- # Delete the alias using quotes
- out = run_cmd(base_app, 'alias delete "fake"')
- assert out == normalize("Alias 'fake' deleted")
-
def test_alias_create_with_quoted_value(base_app, capsys):
"""Demonstrate that quotes in alias value will be preserved (except for redirectors)"""
@@ -1962,22 +1946,6 @@ def test_macro_create(base_app, capsys):
out = run_cmd(base_app, 'macro list fake')
assert out == normalize('macro create fake pyscript')
-def test_macro_create_quoted_name(base_app, capsys):
- """Demonstrate that names can be quoted in macro commands because they will be stripped"""
- # Create the macro
- out = run_cmd(base_app, 'macro create "fake" pyscript')
-
- # The quotes on names are stripped
- assert out == normalize("Macro 'fake' created")
-
- # Look up the new macro and quote the name
- out = run_cmd(base_app, 'macro list "fake"')
- assert out == normalize('macro create fake pyscript')
-
- # Delete the macro using quotes
- out = run_cmd(base_app, 'macro delete "fake"')
- assert out == normalize("Macro 'fake' deleted")
-
def test_macro_create_with_quoted_value(base_app, capsys):
"""Demonstrate that quotes in macro value will be preserved (except for redirectors)"""
# Create the macro