tools: fix handling single optional VM name

This commit is contained in:
Marek Marczykowski-Górecki 2017-05-18 09:50:25 +02:00
parent ee81902979
commit 7f5fc6ac3d
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

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