Revision 54d800e8 kamaki/cli/command_shell.py

b/kamaki/cli/command_shell.py
37 37

  
38 38
from kamaki.cli import _exec_cmd, _print_error_message
39 39
from kamaki.cli.argument import ArgumentParseManager
40
from kamaki.cli.utils import print_dict, split_input
40
from kamaki.cli.utils import print_dict, split_input, print_items
41 41
from kamaki.cli.history import History
42 42
from kamaki.cli.errors import CLIError
43 43

  
......
165 165
            if subcmd.is_command:  # exec command
166 166
                cls = subcmd.get_class()
167 167
                instance = cls(dict(cmd_parser.arguments))
168
                cmd_parser.syntax = '%s %s' % (
169
                    subcmd.path.replace('_', ' '), cls.syntax)
170 168
                cmd_parser.update_arguments(instance.arguments)
171 169
                instance.arguments.pop('config')
172
                cmd_parser = ArgumentParseManager(cmd_parser.syntax,
170
                cmd_parser = ArgumentParseManager(subcmd.path,
173 171
                    instance.arguments)
172
                cmd_parser.syntax = '%s %s' % (
173
                    subcmd.path.replace('_', ' '), cls.syntax)
174 174
                if '-h' in cmd_args or '--help' in cmd_args:
175 175
                    cmd_parser.parser.print_help()
176
                    print('\n%s' % subcmd.help)
176 177
                    return
177 178
                cmd_parser.parse(cmd_args)
178 179

  
......
208 209

  
209 210
        def help_method(self):
210 211
            print('%s (%s -h for more options)' % (cmd.help, cmd.name))
212
            if cmd.is_command:
213
                cls = cmd.get_class()
214
                #_construct_command_syntax(cls)
215
                plist = self.prompt[len(self._prefix):-len(self._suffix)]
216
                plist = plist.split(' ')
217
                clist = cmd.path.split('_')
218
                upto = 0
219
                for i, term in enumerate(plist):
220
                    try:
221
                        if clist[i] == term:
222
                            upto += 1
223
                    except IndexError:
224
                        break
225
                print('Syntax: %s %s' % (' '.join(clist[upto:]), cls.syntax))
226
            else:
227
                options = dict(name='Options:')
228
                for sub in cmd.get_subcommands():
229
                    options[sub.name] = sub.help
230
                print_items([options])
231

  
211 232
        self._register_method(help_method, 'help_%s' % cmd.name)
212 233

  
213 234
        def complete_method(self, text, line, begidx, endidx):

Also available in: Unified diff