toos: fix handling default command (qvm-device, qvm-volume, ...)

When command isn't specified, command variable is set to None. Lets
handle this situation gracefuly.
This commit is contained in:
Marek Marczykowski-Górecki 2017-05-30 01:39:35 +02:00
parent 065eb036df
commit a184e35a03
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 9 additions and 0 deletions

View File

@ -389,6 +389,8 @@ class QubesArgumentParser(argparse.ArgumentParser):
argparse._SubParsersAction): # pylint: disable=no-member
assert hasattr(namespace, 'command')
command = namespace.command
if command is None:
continue
subparser = action._name_parser_map[command]
for subaction in subparser._actions:
if issubclass(subaction.__class__, QubesAction):

View File

@ -201,6 +201,10 @@ def get_parser(device_class=None):
else:
parser.add_argument('devclass', metavar='DEVICE_CLASS', action='store',
help="Device class to manage ('pci', 'usb', etc)")
# default action
parser.set_defaults(func=list_devices)
sub_parsers = parser.add_subparsers(
title='commands',
description="For more information see qvm-device command -h",

View File

@ -192,6 +192,7 @@ def init_extend_parser(sub_parsers):
extend_parser.add_argument('size', help='New size in bytes')
extend_parser.set_defaults(func=extend_volumes)
def get_parser():
'''Create :py:class:`argparse.ArgumentParser` suitable for
:program:`qvm-block`.
@ -207,6 +208,8 @@ def get_parser():
init_extend_parser(sub_parsers)
init_list_parser(sub_parsers)
init_revert_parser(sub_parsers)
# default action
parser.set_defaults(func=list_volumes)
return parser