Browse Source

qvm-prefs: add --hide-default option

Malte Leip 5 years ago
parent
commit
32538fa5ec

+ 4 - 0
doc/manpages/qubes-prefs.rst

@@ -19,6 +19,10 @@ Options
 
    List available properties with short descriptions and exit.
 
+.. option:: --hide-default
+
+   Do not show properties that are set to the default value.
+
 .. option:: --verbose, -v
 
    Increase verbosity.

+ 4 - 0
doc/manpages/qvm-prefs.rst

@@ -19,6 +19,10 @@ Options
 
    List available properties with short descriptions and exit.
 
+.. option:: --hide-default
+
+   Do not show properties that are set to the default value.
+
 .. option:: --verbose, -v
 
    Increase verbosity.

+ 5 - 0
qubesadmin/tests/tools/qubes_prefs.py

@@ -39,6 +39,11 @@ class TC_00_qubes_prefs(qubesadmin.tests.QubesTestCase):
         self.assertEqual(stdout.getvalue(),
             'prop1  D  value1\n'
             'prop2  -  value2\n')
+        with qubesadmin.tests.tools.StdoutBuffer() as stdout:
+            self.assertEqual(0, qubesadmin.tools.qubes_prefs.main([
+                '--hide-default'], app=self.app))
+        self.assertEqual(stdout.getvalue(),
+            'prop2  -  value2\n')
         self.assertAllCalled()
 
     def test_002_set_property(self):

+ 5 - 0
qubesadmin/tests/tools/qvm_prefs.py

@@ -44,6 +44,11 @@ class TC_00_qvm_prefs(qubesadmin.tests.QubesTestCase):
         self.assertEqual(stdout.getvalue(),
             'prop1  D  value1\n'
             'prop2  -  value2\n')
+        with qubesadmin.tests.tools.StdoutBuffer() as stdout:
+            self.assertEqual(0, qubesadmin.tools.qvm_prefs.main([
+                'dom0','--hide-default'], app=self.app))
+        self.assertEqual(stdout.getvalue(),
+            'prop2  -  value2\n')
         self.assertAllCalled()
 
     def test_001_no_vm(self):

+ 0 - 2
qubesadmin/tools/qubes_prefs.py

@@ -20,8 +20,6 @@
 
 ''' Manipulate global properties.'''
 
-# TODO list only non-default properties
-
 from __future__ import print_function
 
 import sys

+ 8 - 5
qubesadmin/tools/qvm_prefs.py

@@ -19,7 +19,6 @@
 # with this program; if not, see <http://www.gnu.org/licenses/>.
 
 ''' Manipulate VM properties.'''
-# TODO list only non-default properties
 
 from __future__ import print_function
 
@@ -41,6 +40,10 @@ def get_parser(vmname_nargs=1):
         action='store_true',
         help='list all available properties with short descriptions and exit')
 
+    parser.add_argument('--hide-default',
+        action='store_true',
+        help='Do not show properties that are set to the default value.')
+
     parser.add_argument('--get', '-g',
         action='store_true',
         help='Ignored; for compatibility with older scripts.')
@@ -101,12 +104,12 @@ def process_actions(parser, args, target):
                     name=prop, width=width))
                 continue
 
-            if target.property_is_default(prop):
-                print('{name:{width}s}  D  {value!s}'.format(
-                    name=prop, width=width, value=value))
-            else:
+            if not target.property_is_default(prop):
                 print('{name:{width}s}  -  {value!s}'.format(
                     name=prop, width=width, value=value))
+            elif not args.hide_default:
+                print('{name:{width}s}  D  {value!s}'.format(
+                    name=prop, width=width, value=value))
 
         return 0
     else: