Skip to content

Commit

Permalink
Hide qvm-prefs default value with --hide-default
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Jul 27, 2024
1 parent c24ff6b commit cc57577
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 14 additions & 0 deletions qubesadmin/tests/tools/qvm_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,17 @@ def test_008_set_vm_prop_none(self):
self.assertEqual(0, qubesadmin.tools.qvm_prefs.main([
'dom0', 'prop1', 'None'], app=self.app))
self.assertAllCalled()

def test_009_hide_default(self):
self.app.expected_calls[
('dom0', 'admin.vm.List', None, None)] = \
b'0\x00dom0 class=AdminVM state=Running\n' \
b'vm1 class=AppVM state=Stopped\n'
self.app.expected_calls[
('dom0', 'admin.vm.property.Get', 'prop1', None)] = \
b'0\x00default=True type=vm vm1'
with qubesadmin.tests.tools.StdoutBuffer() as stdout:
qubesadmin.tools.qvm_prefs.main(['dom0', 'prop1', '--hide-default'],
app=self.app)
self.assertEqual('', stdout.getvalue())
self.assertAllCalled()
9 changes: 6 additions & 3 deletions qubesadmin/tools/qvm_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ def process_actions(parser, args, target):
return 0

try:
value = getattr(target, args.property)
if value is not None:
print(str(value))
if target.property_is_default(args.property) and args.hide_default:
return 0
else:
value = getattr(target, args.property)
if value is not None:
print(str(value))
except qubesadmin.exc.QubesNoSuchPropertyError:
parser.error('no such property: {!r}'.format(args.property))
except qubesadmin.exc.QubesException as e:
Expand Down

0 comments on commit cc57577

Please sign in to comment.