From a184e35a036c72769cb906750ff678e3bf2dd4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 30 May 2017 01:39:35 +0200 Subject: [PATCH] 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. --- qubesadmin/tools/__init__.py | 2 ++ qubesadmin/tools/qvm_device.py | 4 ++++ qubesadmin/tools/qvm_volume.py | 3 +++ 3 files changed, 9 insertions(+) diff --git a/qubesadmin/tools/__init__.py b/qubesadmin/tools/__init__.py index 83fdea4..ec46e3a 100644 --- a/qubesadmin/tools/__init__.py +++ b/qubesadmin/tools/__init__.py @@ -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): diff --git a/qubesadmin/tools/qvm_device.py b/qubesadmin/tools/qvm_device.py index 53d4cd8..653ec19 100644 --- a/qubesadmin/tools/qvm_device.py +++ b/qubesadmin/tools/qvm_device.py @@ -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", diff --git a/qubesadmin/tools/qvm_volume.py b/qubesadmin/tools/qvm_volume.py index 75c8928..408891f 100644 --- a/qubesadmin/tools/qvm_volume.py +++ b/qubesadmin/tools/qvm_volume.py @@ -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