From 7f5fc6ac3d904a5c6365089cfa91188807832742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 18 May 2017 09:50:25 +0200 Subject: [PATCH] tools: fix handling single optional VM name --- qubesadmin/tools/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/qubesadmin/tools/__init__.py b/qubesadmin/tools/__init__.py index 3dadde1..83fdea4 100644 --- a/qubesadmin/tools/__init__.py +++ b/qubesadmin/tools/__init__.py @@ -163,11 +163,19 @@ class VmNameAction(QubesAction): if hasattr(namespace, 'exclude') and namespace.exclude: parser.error('--exclude can only be used with --all') - for vm_name in getattr(namespace, self.dest): - try: - namespace.domains += [app.domains[vm_name]] - except KeyError: - parser.error('no such domain: {!r}'.format(vm_name)) + if self.nargs == argparse.OPTIONAL: + vm_name = getattr(namespace, self.dest, None) + if vm_name is not None: + try: + namespace.domains += [app.domains[vm_name]] + except KeyError: + parser.error('no such domain: {!r}'.format(vm_name)) + else: + for vm_name in getattr(namespace, self.dest): + try: + namespace.domains += [app.domains[vm_name]] + except KeyError: + parser.error('no such domain: {!r}'.format(vm_name)) class RunningVmNameAction(VmNameAction):