[BUILD] Improve docker images download script testability 02/127502/1
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Fri, 4 Mar 2022 15:29:38 +0000 (16:29 +0100)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Fri, 4 Mar 2022 15:29:38 +0000 (16:29 +0100)
Command line argument parsing routine now returns raw ArgumentParser
object for easier instantiation in test routines.

Change-Id: Icac599a6e72b0a7514a1a33d23624c44dc819b9b
Issue-ID: INT-1429
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
build/download/download.py

index 94cc1b5..d47462c 100755 (executable)
@@ -78,14 +78,7 @@ def parse_args():
                         help='Check what is missing. No download.')
     parser.add_argument('--debug', action='store_true', default=False,
                         help='Turn on debug output')
-
-    args = parser.parse_args()
-
-    for arg in ('docker', 'npm', 'http', 'rpm', 'git', 'pypi'):
-        if getattr(args, arg):
-            return args
-
-    parser.error('One of --docker, --npm, --http, --rpm, --git or --pypi must be specified')
+    return parser
 
 
 def log_start(item_type):
@@ -156,7 +149,15 @@ def run_cli():
     if sys.version_info.major < 3:
         log.error('Unfortunately Python 2 is not supported for data download.')
         sys.exit(1)
-    args = parse_args()
+
+    parser = parse_args()
+    args = parser.parse_args()
+
+    for arg in ('docker', 'npm', 'http', 'rpm', 'git', 'pypi'):
+        if getattr(args, arg):
+            break
+        else:
+            parser.error('One of --docker, --npm, --http, --rpm, --git or --pypi must be specified')
 
     console_handler = logging.StreamHandler(sys.stdout)
     console_formatter = logging.Formatter('%(message)s')