Revision 49e85ee2 kamaki/cli/argument/__init__.py
b/kamaki/cli/argument/__init__.py | ||
---|---|---|
394 | 394 |
class ArgumentParseManager(object): |
395 | 395 |
"""Manage (initialize and update) an ArgumentParser object""" |
396 | 396 |
|
397 |
def __init__(self, exe, arguments=None, required=None): |
|
397 |
def __init__( |
|
398 |
self, exe, |
|
399 |
arguments=None, required=None, syntax=None, description=None): |
|
398 | 400 |
""" |
399 | 401 |
:param exe: (str) the basic command (e.g. 'kamaki') |
400 | 402 |
|
... | ... | |
412 | 414 |
['b', 'c']] means that the command required either 'a' and 'b' or |
413 | 415 |
'a' and 'c' or at least one of 'b', 'c' and could be written as |
414 | 416 |
[('a', ['b', 'c']), ['b', 'c']] |
417 |
:param syntax: (str) The basic syntax of the arguments. Default: |
|
418 |
exe <cmd_group> [<cmd_subbroup> ...] <cmd> |
|
419 |
:param description: (str) The description of the commands or '' |
|
415 | 420 |
""" |
416 | 421 |
self.parser = ArgumentParser( |
417 | 422 |
add_help=False, formatter_class=RawDescriptionHelpFormatter) |
418 | 423 |
self._exe = exe |
419 |
self.syntax = '%s <cmd_group> [<cmd_subbroup> ...] <cmd>' % exe |
|
424 |
self.syntax = syntax or ( |
|
425 |
'%s <cmd_group> [<cmd_subbroup> ...] <cmd>' % exe) |
|
420 | 426 |
self.required = required |
427 |
self.parser.description = description or '' |
|
421 | 428 |
if arguments: |
422 | 429 |
self.arguments = arguments |
423 | 430 |
else: |
... | ... | |
555 | 562 |
pkargs = (new_args,) if new_args else () |
556 | 563 |
self._parsed, unparsed = self.parser.parse_known_args(*pkargs) |
557 | 564 |
pdict = vars(self._parsed) |
558 |
diff = set(self.required or []).difference([
|
|
559 |
k for k in pdict if pdict[k] != None])
|
|
565 |
diff = set(self.required or []).difference( |
|
566 |
[k for k in pdict if pdict[k] not in (None, )])
|
|
560 | 567 |
if diff: |
561 | 568 |
self.print_help() |
562 | 569 |
miss = ['/'.join(self.arguments[k].parsed_name) for k in diff] |
Also available in: Unified diff