Revision eb46e9a1
b/kamaki/cli/__init__.py | ||
---|---|---|
348 | 348 |
try: |
349 | 349 |
for cmd in cmds: |
350 | 350 |
if cmd.name in acceptable_groups: |
351 |
descriptions[cmd.name] = cmd.description
|
|
351 |
descriptions[cmd.name] = cmd.help
|
|
352 | 352 |
except TypeError: |
353 | 353 |
if _debug: |
354 | 354 |
kloger.warning( |
355 |
'No cmd description for module %s' % cmd_group) |
|
355 |
'No cmd description (help) for module %s' % cmd_group)
|
|
356 | 356 |
elif _debug: |
357 | 357 |
kloger.warning('Loading of %s cmd spec failed' % cmd_group) |
358 | 358 |
print('\nOptions:\n - - - -') |
... | ... | |
381 | 381 |
|
382 | 382 |
def print_subcommands_help(cmd): |
383 | 383 |
printout = {} |
384 |
for subcmd in cmd.get_subcommands():
|
|
384 |
for subcmd in cmd.subcommands.values():
|
|
385 | 385 |
spec, sep, print_path = subcmd.path.partition('_') |
386 |
printout[print_path.replace('_', ' ')] = subcmd.description
|
|
386 |
printout[print_path.replace('_', ' ')] = subcmd.help
|
|
387 | 387 |
if printout: |
388 | 388 |
print('\nOptions:\n - - - -') |
389 | 389 |
print_dict(printout) |
... | ... | |
396 | 396 |
|
397 | 397 |
description = '' |
398 | 398 |
if cmd.is_command: |
399 |
cls = cmd.get_class()
|
|
399 |
cls = cmd.cmd_class
|
|
400 | 400 |
parser.syntax += ' ' + cls.syntax |
401 | 401 |
parser.update_arguments(cls().arguments) |
402 |
description = getattr(cls, 'long_description', '') |
|
403 |
description = description.strip() |
|
402 |
description = getattr(cls, 'long_description', '').strip() |
|
404 | 403 |
else: |
405 | 404 |
parser.syntax += ' <...>' |
406 |
if cmd.has_description: |
|
407 |
parser.parser.description = cmd.help + ( |
|
408 |
('\n%s' % description) if description else '') |
|
409 |
else: |
|
410 |
parser.parser.description = description |
|
405 |
parser.parser.description = ( |
|
406 |
cmd.help + ('\n' if description else '')) if cmd.help else description |
|
411 | 407 |
|
412 | 408 |
|
413 | 409 |
def print_error_message(cli_err): |
b/kamaki/cli/command_shell.py | ||
---|---|---|
197 | 197 |
# exec command or change context |
198 | 198 |
if subcmd.is_command: # exec command |
199 | 199 |
try: |
200 |
cls = subcmd.get_class()
|
|
200 |
cls = subcmd.cmd_class
|
|
201 | 201 |
ldescr = getattr(cls, 'long_description', '') |
202 | 202 |
if subcmd.path == 'history_run': |
203 | 203 |
instance = cls( |
... | ... | |
241 | 241 |
old_prompt = self.prompt |
242 | 242 |
new_context._roll_command(cmd.parent_path) |
243 | 243 |
new_context.set_prompt(subcmd.path.replace('_', ' ')) |
244 |
newcmds = [subcmd for subcmd in subcmd.get_subcommands()]
|
|
244 |
newcmds = [subcmd for subcmd in subcmd.subcommands.values()]
|
|
245 | 245 |
for subcmd in newcmds: |
246 | 246 |
new_context._register_command(subcmd.path) |
247 | 247 |
new_context.cmdloop() |
... | ... | |
253 | 253 |
def help_method(self): |
254 | 254 |
print('%s (%s -h for more options)' % (cmd.help, cmd.name)) |
255 | 255 |
if cmd.is_command: |
256 |
cls = cmd.get_class()
|
|
256 |
cls = cmd.cmd_class
|
|
257 | 257 |
ldescr = getattr(cls, 'long_description', '') |
258 | 258 |
#_construct_command_syntax(cls) |
259 | 259 |
plist = self.prompt[len(self._prefix):-len(self._suffix)] |
... | ... | |
277 | 277 |
def complete_method(self, text, line, begidx, endidx): |
278 | 278 |
subcmd, cmd_args = cmd.parse_out(split_input(line)[1:]) |
279 | 279 |
if subcmd.is_command: |
280 |
cls = subcmd.get_class()
|
|
280 |
cls = subcmd.cmd_class
|
|
281 | 281 |
instance = cls(dict(arguments)) |
282 | 282 |
empty, sep, subname = subcmd.path.partition(cmd.path) |
283 | 283 |
cmd_name = '%s %s' % (cmd.name, subname.replace('_', ' ')) |
284 | 284 |
print('\n%s\nSyntax:\t%s %s' % ( |
285 |
cls.description, cmd_name, cls.syntax))
|
|
285 |
cls.help, cmd_name, cls.syntax))
|
|
286 | 286 |
cmd_args = {} |
287 | 287 |
for arg in instance.arguments.values(): |
288 | 288 |
cmd_args[','.join(arg.parsed_name)] = arg.help |
b/kamaki/cli/command_tree/__init__.py | ||
---|---|---|
71 | 71 |
|
72 | 72 |
@property |
73 | 73 |
def is_command(self): |
74 |
return self.cmd_class is not None and len(self.subcommands) == 0 |
|
75 |
|
|
76 |
@property |
|
77 |
def has_description(self): |
|
78 |
return len(self.help.strip()) > 0 |
|
79 |
|
|
80 |
@property |
|
81 |
def description(self): |
|
82 |
return self.help |
|
74 |
return len(self.subcommands) == 0 if self.cmd_class else False |
|
83 | 75 |
|
84 | 76 |
@property |
85 | 77 |
def parent_path(self): |
86 |
parentpath, sep, name = self.path.rpartition('_') |
|
87 |
return parentpath |
|
88 |
|
|
89 |
def set_class(self, cmd_class): |
|
90 |
self.cmd_class = cmd_class |
|
91 |
|
|
92 |
def get_class(self): |
|
93 |
return self.cmd_class |
|
94 |
|
|
95 |
def has_subname(self, subname): |
|
96 |
return subname in self.subcommands |
|
97 |
|
|
98 |
def get_subnames(self): |
|
99 |
return self.subcommands.keys() |
|
100 |
|
|
101 |
def get_subcommands(self): |
|
102 |
return self.subcommands.values() |
|
103 |
|
|
104 |
def sublen(self): |
|
105 |
return len(self.subcommands) |
|
78 |
try: |
|
79 |
return self.path[self.path.rindex('_') + 1:] |
|
80 |
except ValueError: |
|
81 |
return '' |
|
106 | 82 |
|
107 | 83 |
def parse_out(self, args): |
108 | 84 |
cmd = self |
... | ... | |
121 | 97 |
self.name, |
122 | 98 |
self.is_command, |
123 | 99 |
self.help)) |
124 |
for cmd in self.get_subcommands():
|
|
100 |
for cmd in self.subcommands.values():
|
|
125 | 101 |
cmd.pretty_print(recursive) |
126 | 102 |
|
127 | 103 |
|
... | ... | |
159 | 135 |
cmd.add_subcmd(new_cmd) |
160 | 136 |
cmd = new_cmd |
161 | 137 |
if cmd_class: |
162 |
cmd.set_class(cmd_class)
|
|
138 |
cmd.cmd_class = cmd_class
|
|
163 | 139 |
if description is not None: |
164 | 140 |
cmd.help = description |
165 | 141 |
|
... | ... | |
205 | 181 |
def get_description(self, path): |
206 | 182 |
return self._all_commands[path].help |
207 | 183 |
|
208 |
def set_class(self, path, cmd_class): |
|
209 |
self._all_commands[path].set_class(cmd_class) |
|
210 |
|
|
211 |
def get_class(self, path): |
|
212 |
return self._all_commands[path].get_class() |
|
213 |
|
|
214 | 184 |
def get_subnames(self, path=None): |
215 | 185 |
if path in (None, ''): |
216 | 186 |
return self.get_group_names() |
217 |
return self._all_commands[path].get_subnames()
|
|
187 |
return self._all_commands[path].subcommands.keys()
|
|
218 | 188 |
|
219 | 189 |
def get_subcommands(self, path=None): |
220 |
if path in (None, ''): |
|
221 |
return self.get_groups() |
|
222 |
return self._all_commands[path].get_subcommands() |
|
190 |
return self._all_commands[path].subcommands.values() if ( |
|
191 |
path) else self.get_groups() |
|
223 | 192 |
|
224 | 193 |
def get_parent(self, path): |
225 | 194 |
if '_' not in path: |
b/kamaki/cli/commands/history.py | ||
---|---|---|
171 | 171 |
if not cmd.is_command: |
172 | 172 |
return |
173 | 173 |
try: |
174 |
instance = cmd.get_class()(
|
|
174 |
instance = cmd.cmd_class(
|
|
175 | 175 |
self.arguments, |
176 | 176 |
auth_base=getattr(self, 'auth_base', None)) |
177 | 177 |
instance.config = self.config |
... | ... | |
180 | 180 |
dict(instance.arguments)) |
181 | 181 |
prs.syntax = '%s %s' % ( |
182 | 182 |
cmd.path.replace('_', ' '), |
183 |
cmd.get_class().syntax)
|
|
183 |
cmd.cmd_class.syntax)
|
|
184 | 184 |
prs.parse(args) |
185 | 185 |
exec_cmd(instance, prs.unparsed, prs.parser.print_help) |
186 | 186 |
except (CLIError, ClientError) as err: |
b/kamaki/cli/one_command.py | ||
---|---|---|
95 | 95 |
print_subcommands_help(cmd) |
96 | 96 |
exit(0) |
97 | 97 |
|
98 |
cls = cmd.get_class()
|
|
98 |
cls = cmd.cmd_class
|
|
99 | 99 |
executable = cls(parser.arguments, auth_base, cloud) |
100 | 100 |
parser.update_arguments(executable.arguments) |
101 | 101 |
#parsed, unparsed = parse_known_args(parser, executable.arguments) |
Also available in: Unified diff