From d07b37962d98684e52eb79f406364b2770f64ba4 Mon Sep 17 00:00:00 2001 From: Stavros Sachtouris Date: Thu, 8 Nov 2012 17:29:20 +0200 Subject: [PATCH] Fix bug with deep-pathed commands FEATURE: subcommands of a callable command are not allowed. e.g.: if the following exist as callable commands: cmd1_cmd2 cmd1_cmd2_cmd3 then cmd1_cmd2 is resolved, but cmd1_cmd2_cmd3 is not UNFIXED: There is still a case of syntax-error or --help call where the best possible help message is not resolved: cmd1_cmd2_cmd3 where cmd1_cmd2 is not a command --- kamaki/cli/__init__.py | 12 ++++++++++-- kamaki/cli/command_tree.py | 2 +- kamaki/cli/commands/quotaholder_cli.py | 24 ++++++++---------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/kamaki/cli/__init__.py b/kamaki/cli/__init__.py index f8df9ec..24a713a 100644 --- a/kamaki/cli/__init__.py +++ b/kamaki/cli/__init__.py @@ -298,13 +298,21 @@ def one_command(): exit(0) cmd = load_command(group, unparsed) + # Find the most specific subcommand + for term in list(unparsed): + if cmd.is_command: + break + if cmd.contains(term): + cmd = cmd.get_subcmd(term) + unparsed.remove(term) + if _help or not cmd.is_command: if cmd.has_description: parser.description = cmd.help else: try: - parser.description\ - = _commands.get_closest_ancestor_command(cmd.path).help + parser.description =\ + _commands.get_closest_ancestor_command(cmd.path).help except KeyError: parser.description = ' ' parser.prog = '%s %s ' % (exe, cmd.path.replace('_', ' ')) diff --git a/kamaki/cli/command_tree.py b/kamaki/cli/command_tree.py index ae77e4c..eff2f32 100644 --- a/kamaki/cli/command_tree.py +++ b/kamaki/cli/command_tree.py @@ -167,7 +167,7 @@ class CommandTree(object): def set_description(self, path, description): self._all_commands[path].help = description - def get_descitpion(self, path): + def get_description(self, path): return self._all_commands[path].help def set_class(self, path, cmd_class): diff --git a/kamaki/cli/commands/quotaholder_cli.py b/kamaki/cli/commands/quotaholder_cli.py index 155a7ad..ad5d47e 100644 --- a/kamaki/cli/commands/quotaholder_cli.py +++ b/kamaki/cli/commands/quotaholder_cli.py @@ -45,34 +45,26 @@ class _quotaholder_init(_command_init): or self.config.get('global', 'token') self.base_url = self.config.get('quotaholder', 'url')\ or self.config.get('global', 'url') - self.client = QuotaHolderClient(self.base_url, self.token) + #self.client = QuotaHolderClient(self.base_url, self.token) + print(self.__class__) @command() class quotaholder_test_specific(_quotaholder_init): - """Test quota holder commands - devel/testing only""" + """quotaholder test specific""" - def main(self): + def main(self, specify): super(self.__class__, self).main() - print('We will test quota holder stuff') - r = self.client.test_quota() - print('That is what we got {%s}' % r) @command() class quotaholder_test_all(_quotaholder_init): - """Test quota holder commands - devel/testing only""" + """quotaholder test all""" def main(self): super(self.__class__, self).main() - print('We will test quota holder stuff') - r = self.client.test_quota() - print('That is what we got {%s}' % r) @command() -class quotaholder_test(_quotaholder_init): - """Test quota holder commands - devel/testing only""" +class quotaholder_test_me(_quotaholder_init): + """quotaholder test""" - def main(self): + def main(self, who='you'): super(self.__class__, self).main() - print('We will test quota holder stuff') - r = self.client.test_quota() - print('That is what we got {%s}' % r) -- 1.7.10.4