support/scripts/pkg-stats: improve argparse usage
authorVictor Huesca <victor.huesca@bootlin.com>
Fri, 19 Jul 2019 13:06:28 +0000 (15:06 +0200)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Thu, 1 Aug 2019 09:10:41 +0000 (11:10 +0200)
Move the mutual exculsion of the '-n' and '-p' options to be part of the
parser instead of being checked in main.

Signed-off-by: Victor Huesca <victor.huesca@bootlin.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
support/scripts/pkg-stats

index b0be7d919b8dcc05a3d98bea11082550c149e92a..d65f609d5771ead29e6f38a9ead6c23fc40b352c 100755 (executable)
@@ -23,7 +23,6 @@ import os
 from collections import defaultdict
 import re
 import subprocess
-import sys
 import requests  # URL checking
 import json
 import certifi
@@ -700,18 +699,16 @@ def parse_args():
     parser = argparse.ArgumentParser()
     parser.add_argument('-o', dest='output', action='store', required=True,
                         help='HTML output file')
-    parser.add_argument('-n', dest='npackages', type=int, action='store',
+    packages = parser.add_mutually_exclusive_group()
+    packages.add_argument('-n', dest='npackages', type=int, action='store',
                         help='Number of packages')
-    parser.add_argument('-p', dest='packages', action='store',
+    packages.add_argument('-p', dest='packages', action='store',
                         help='List of packages (comma separated)')
     return parser.parse_args()
 
 
 def __main__():
     args = parse_args()
-    if args.npackages and args.packages:
-        print("ERROR: -n and -p are mutually exclusive")
-        sys.exit(1)
     if args.packages:
         package_list = args.packages.split(",")
     else: