diff options
author | Lars Wirzenius <liw@liw.fi> | 2013-10-30 11:54:33 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2013-10-30 11:54:33 +0000 |
commit | f15a74ce3cc2c2b0de3cab876ed00bbc31ecf1fd (patch) | |
tree | 9be8cfd49f303dc781d1030d7ff0a819a9cfc141 /cliapp/app.py | |
parent | 9c4a905d3985d361f0b5362a5ed6d480a5b09404 (diff) | |
download | cliapp-f15a74ce3cc2c2b0de3cab876ed00bbc31ecf1fd.tar.gz |
Check subcommand validity outside formatter
Diffstat (limited to 'cliapp/app.py')
-rw-r--r-- | cliapp/app.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/cliapp/app.py b/cliapp/app.py index abffa45..cf75116 100644 --- a/cliapp/app.py +++ b/cliapp/app.py @@ -293,8 +293,11 @@ class Application(object): fmt = self.get_help_text_formatter(width=width) if args: - usage = self._format_usage_for(args[0]) - description = fmt.format(self._format_subcommand_help(args[0])) + cmd = args[0] + if cmd not in self.subcommands: + raise cliapp.AppException('Unknown subcommand %s' % cmd) + usage = self._format_usage_for(cmd) + description = fmt.format(self._format_subcommand_help(cmd)) text = '%s\n\n%s' % (usage, description) else: usage = self._format_usage(all=show_all) @@ -367,8 +370,6 @@ class Application(object): return '* %%prog %s: %s\n' % (cmd, summary) def _format_subcommand_help(self, cmd): # pragma: no cover - if cmd not in self.subcommands: - raise cliapp.AppException('Unknown subcommand %s' % cmd) method = self.subcommands[cmd] doc = method.__doc__ or '' t = doc.split('\n', 1) |