From 6e6220eb36a1df77f45e6affeaa02fd114ed9fd4 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Wed, 7 Aug 2019 18:52:50 -0400 Subject: Verifying command names in __init__ --- cmd2/cmd2.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cmd2/cmd2.py') 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 -- cgit v1.2.1