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):