diff options
author | Eric Lin <anselor@gmail.com> | 2020-08-20 11:34:45 -0400 |
---|---|---|
committer | Eric Lin <anselor@gmail.com> | 2020-08-20 13:35:18 -0400 |
commit | 9a20e7ca66bdab4581409d1eac16c931db08d6b6 (patch) | |
tree | c7b2d92bc45ef662c4829d417180a89167b7890b /cmd2/cmd2.py | |
parent | 30d010f62196ff082bf243a4c460517cb70c70f2 (diff) | |
download | cmd2-git-9a20e7ca66bdab4581409d1eac16c931db08d6b6.tar.gz |
Added validation of subcommand handler attributes
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index adf797bf..f6a5251c 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -637,10 +637,14 @@ class Cmd(cmd.Cmd): # iterate through all matching methods for method_name, method in methods: - subcommand_name = getattr(method, constants.SUBCMD_ATTR_NAME) + subcommand_name = getattr(method, constants.SUBCMD_ATTR_NAME) # type: str full_command_name = getattr(method, constants.SUBCMD_ATTR_COMMAND) # type: str subcmd_parser = getattr(method, constants.CMD_ATTR_ARGPARSER) + subcommand_valid, errmsg = self.statement_parser.is_valid_command(subcommand_name, is_subcommand=True) + if not subcommand_valid: + raise CommandSetRegistrationError('Subcommand {} is not valid: {}'.format(str(subcommand_name), errmsg)) + command_tokens = full_command_name.split() command_name = command_tokens[0] subcommand_names = command_tokens[1:] |