Fix bug with deep-pathed commands
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 8 Nov 2012 15:29:20 +0000 (17:29 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 8 Nov 2012 15:29:20 +0000 (17:29 +0200)
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
kamaki/cli/command_tree.py
kamaki/cli/commands/quotaholder_cli.py

index f8df9ec..24a713a 100644 (file)
@@ -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('_', ' '))
index ae77e4c..eff2f32 100644 (file)
@@ -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):
index 155a7ad..ad5d47e 100644 (file)
@@ -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)