diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-09-26 14:37:13 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-09-26 14:37:13 -0400 |
commit | 8aeb29cf1fd027093b87b8f9f9c640cf50595db7 (patch) | |
tree | 23cb1ef06b4f9e52fe8b6da0b7e9f51a05e609e1 /cmd2/parsing.py | |
parent | 149f6eba2620b1623f6071227318450c779b2b50 (diff) | |
parent | c8983d9d6df4d057672166a7e8df544199788b9a (diff) | |
download | cmd2-git-8aeb29cf1fd027093b87b8f9f9c640cf50595db7.tar.gz |
Merge branch 'macro' into argparse_conversion
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r-- | cmd2/parsing.py | 13 |
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 = [] |