]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu-gather: Use actions instead of flags for action argument
authorTim Wiederhake <twiederh@redhat.com>
Mon, 4 Jan 2021 11:30:17 +0000 (12:30 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 7 Jan 2021 17:11:07 +0000 (18:11 +0100)
This allows for the functionality of cpu-cpuid.py script to be
integrated more naturally in a later patch.

Changes the way this script should be called:
  cpu-gather.py                   -> cpu-gather.py
  cpu-gather.py --gather          -> cpu-gather.py gather
  cpu-gather.py --parse           -> cpu-gather.py parse
  cpu-gather.py --gather --parse  -> cpu-gather.py full

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
tests/cputestdata/cpu-gather.py

index a01c615504f5bf6a20e65649fe8a737e270db5fc..5ca19e5f2b4f22e5e90394787438d8c999153eba 100755 (executable)
@@ -324,21 +324,22 @@ def main():
         help="Path to qemu. "
         "If unset, will try '/usr/bin/qemu-system-x86_64', "
         "'/usr/bin/qemu-kvm', and '/usr/libexec/qemu-kvm'.")
-    parser.add_argument(
-        "--gather",
-        action="store_true",
-        help="Acquire data on target system. This is the default. "
-        "If '--parse' is not set, outputs data on stdout.")
-    parser.add_argument(
-        "--parse",
-        action="store_true",
-        help="Parse data for libvirt use. "
-        "If '--gather' is not set, expects input on stdin.")
+    subparsers = parser.add_subparsers(dest="action")
+    subparsers.add_parser(
+        "gather",
+        help="Acquire data on target system and outputs to stdout. "
+        "This is the default. ")
+    subparsers.add_parser(
+        "parse",
+        help="Reads data from stdin and parses data for libvirt use.")
+    subparsers.add_parser(
+        "full",
+        help="Equivalent to `cpu-gather gather | cpu-gather parse`.")
 
     args = parser.parse_args()
 
-    if not args.gather and not args.parse:
-        args.gather = True
+    if not args.action:
+        args.action = "gather"
 
     if not args.path_to_qemu:
         args.path_to_qemu = "qemu-system-x86_64"
@@ -350,13 +351,13 @@ def main():
             if os.path.isfile(f):
                 args.path_to_qemu = f
 
-    if args.gather:
+    if args.action in ["gather", "full"]:
         data = gather(args)
-        if not args.parse:
+        if args.action == "gather":
             json.dump(data, sys.stdout, indent=2)
 
-    if args.parse:
-        if not args.gather:
+    if args.action in ["parse", "full"]:
+        if args.action == "parse":
             data = json.load(sys.stdin)
         parse(data)