Skip to content

Commit 0724d38

Browse files
committed
Allow an alias name to match a command name
1 parent ad76cec commit 0724d38

2 files changed

Lines changed: 3 additions & 14 deletions

File tree

cmd2.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,9 +2105,9 @@ def complete(self, text, state):
21052105

21062106
else:
21072107
# Complete token against aliases and command names
2108-
alias_names = list(self.aliases.keys())
2109-
visible_commands = self.get_visible_commands()
2110-
strs_to_match = alias_names + visible_commands
2108+
alias_names = set(self.aliases.keys())
2109+
visible_commands = set(self.get_visible_commands())
2110+
strs_to_match = list(alias_names | visible_commands)
21112111
self.completion_matches = self.basic_complete(text, line, begidx, endidx, strs_to_match)
21122112

21132113
# Handle single result
@@ -2755,12 +2755,6 @@ def do_alias(self, arglist):
27552755
name = arglist[0]
27562756
value = ' '.join(arglist[1:])
27572757

2758-
# Make sure the alias does not match an existing command
2759-
cmd_func = self._func_named(name)
2760-
if cmd_func is not None:
2761-
self.perror("Alias names cannot match an existing command: {!r}".format(name), traceback_war=False)
2762-
return
2763-
27642758
# Check for a valid name
27652759
for cur_char in name:
27662760
if cur_char not in self.identchars:

tests/test_cmd2.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,11 +1560,6 @@ def test_alias(base_app, capsys):
15601560
out = run_cmd(base_app, 'alias')
15611561
assert out == normalize('alias fake pyscript')
15621562

1563-
def test_alias_with_cmd_name(base_app, capsys):
1564-
run_cmd(base_app, 'alias help eos')
1565-
out, err = capsys.readouterr()
1566-
assert "cannot match an existing command" in err
1567-
15681563
def test_alias_with_invalid_name(base_app, capsys):
15691564
run_cmd(base_app, 'alias @ help')
15701565
out, err = capsys.readouterr()

0 commit comments

Comments
 (0)