Skip to content

Commit f723b35

Browse files
committed
Java: improve argument handling of pick-best-jars.py
1 parent c5449ec commit f723b35

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

java/maven-indexer/pick-best-jars.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Classes-in-package ascending should favour newer versions of a package (which typically define less classes) and/or selective shades which have picked a few classes to include
66
# Classes-out-of-package should exclude jars that have shaded this package in, and/or projects distributed as individual modules as well as an `-all` package.
77

8+
import argparse
89
import re
910
import sys
1011
import os.path
@@ -287,16 +288,26 @@ def adjust_output_jars(jars):
287288
return jars
288289

289290
if __name__ == '__main__':
291+
parser = argparse.ArgumentParser(
292+
prog='pick-best-jars.py',
293+
description='Pick the best jars to provide a given package'
294+
)
295+
parser.add_argument('jar_repository_dir', help='Directory containing the jar files to consider')
296+
parser.add_argument('input_file', help='File containing the packages to consider')
297+
parser.add_argument('output_file', help='File to write the results to')
298+
parser.add_argument('-j', '--max-workers', help='Maximum number of worker processes to use', type=int)
299+
parser.add_argument('--verbose', help='Print verbose output', action='store_true')
300+
parser.add_argument('--explain', help='Explain the choice of jar for the given package', action='append', default=[])
301+
args = parser.parse_args()
302+
jar_repository_dir = args.jar_repository_dir
303+
input_file = args.input_file
304+
output_file = args.output_file
305+
verbose = args.verbose
306+
max_workers = args.max_workers
307+
explain_packages = args.explain
308+
# replace '.' with '/' in package names
309+
explain_packages = [p.replace('.', '/') for p in explain_packages]
290310

291-
jar_repository_dir = sys.argv[1]
292-
input_file = sys.argv[2]
293-
output_file = sys.argv[3]
294-
295-
verbose = any(a == "--verbose" for a in sys.argv)
296-
max_workers_arg = [a for a in sys.argv if a.startswith("-j")]
297-
max_workers = int(max_workers_arg[-1][2:]) if len(max_workers_arg) > 0 else None
298-
explain_arg = [a for a in sys.argv if a.startswith("--explain=")]
299-
explain_packages = [a[len("--explain="):] for a in explain_arg]
300311
if len(explain_packages) != 0:
301312
verbose = True
302313

0 commit comments

Comments
 (0)