diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-08-07 18:52:50 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-08-07 18:52:50 -0400 |
commit | 6e6220eb36a1df77f45e6affeaa02fd114ed9fd4 (patch) | |
tree | 187a54954c401a11c79cb2d817226a1e282ab09f /cmd2/cmd2.py | |
parent | 89a5a646ffa2f72154b932f0b2dbf23fd87866e3 (diff) | |
download | cmd2-git-6e6220eb36a1df77f45e6affeaa02fd114ed9fd4.tar.gz |
Verifying command names in __init__
Diffstat (limited to 'cmd2/cmd2.py')
-rwxr-xr-x | cmd2/cmd2.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index d82e58c9..305c4173 100755 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -448,6 +448,12 @@ class Cmd(cmd.Cmd): multiline_commands=multiline_commands, shortcuts=shortcuts) + # Verify commands don't have invalid names (like starting with a shortcut) + for cmd in self.get_all_commands(): + valid, errmsg = self.statement_parser.is_valid_command(cmd) + if not valid: + raise ValueError("Invalid command name {!r}: {}".format(cmd, errmsg)) + # Stores results from the last command run to enable usage of results in a Python script or interactive console # Built-in commands don't make use of this. It is purely there for user-defined commands and convenience. self.last_result = None |