@@ -416,9 +416,10 @@ class DeviceAction(qubesadmin.tools.QubesAction):
416
416
""" # pylint: disable=too-few-public-methods
417
417
418
418
def __init__ (self , help = 'A backend, port & device id combination' ,
419
- required = True , allow_unknown = False , ** kwargs ):
419
+ required = True , allow_unknown = False , only_port = False , ** kwargs ):
420
420
# pylint: disable=redefined-builtin
421
421
self .allow_unknown = allow_unknown
422
+ self .only_port = only_port
422
423
super ().__init__ (help = help , required = required , ** kwargs )
423
424
424
425
def __call__ (self , parser , namespace , values , option_string = None ):
@@ -445,6 +446,12 @@ def parse_qubes_app(self, parser, namespace):
445
446
_dev = dev .backend_domain .devices [devclass ][dev .port_id ]
446
447
if not dev .is_device_id_set or dev .device_id == _dev .device_id :
447
448
dev = _dev
449
+ elif self .only_port :
450
+ parser .error_runtime (
451
+ "this option works only for explicitly given port ID "
452
+ "and does not support device ID" )
453
+ else :
454
+ dev = UnknownDevice .from_device (dev )
448
455
if not self .allow_unknown and isinstance (dev , UnknownDevice ):
449
456
raise KeyError (dev .port_id )
450
457
except KeyError :
@@ -524,7 +531,7 @@ def get_parser(device_class=None):
524
531
info_parser .add_argument (metavar = 'BACKEND:DEVICE_ID' ,
525
532
dest = 'device' ,
526
533
nargs = argparse .OPTIONAL ,
527
- action = DeviceAction , allow_unknown = True )
534
+ action = DeviceAction , only_port = True )
528
535
529
536
option = (('--option' , '-o' ,),
530
537
{'action' : 'append' ,
0 commit comments