summaryrefslogtreecommitdiff
path: root/cmd2/parsing.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r--cmd2/parsing.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py
index 498834cf..82e8ee39 100644
--- a/cmd2/parsing.py
+++ b/cmd2/parsing.py
@@ -291,7 +291,7 @@ class StatementParser:
expr = r'\A\s*(\S*?)({})'.format(second_group)
self._command_pattern = re.compile(expr)
- def is_valid_command(self, word: str) -> Tuple[bool, str]:
+ def is_valid_command(self, word: str, allow_shortcut: bool) -> Tuple[bool, str]:
"""Determine whether a word is a valid name for a command.
Commands can not include redirection characters, whitespace,
@@ -311,11 +311,12 @@ class StatementParser:
if not word:
return False, 'cannot be an empty string'
- errmsg = 'cannot start with a shortcut: '
- errmsg += ', '.join(shortcut for (shortcut, expansion) in self.shortcuts)
- for (shortcut, expansion) in self.shortcuts:
- if word.startswith(shortcut):
- return False, errmsg
+ if not allow_shortcut:
+ errmsg = 'cannot start with a shortcut: '
+ errmsg += ', '.join(shortcut for (shortcut, expansion) in self.shortcuts)
+ for (shortcut, expansion) in self.shortcuts:
+ if word.startswith(shortcut):
+ return False, errmsg
errmsg = 'cannot contain: whitespace, quotes, '
errchars = []