From 37067a53c4b3b99982ef8e1f431ba0c9302b66e8 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sun, 13 May 2018 10:36:58 -0400 Subject: Use a single ArgumentParser for all subcommands This has the adventage that "meson --help" shows a list of all commands, making them discoverable. This also reduce the manual parsing of arguments to the strict minimum needed for backward compatibility. --- mesonbuild/mtest.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'mesonbuild/mtest.py') diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index 8d9a585..78f2252 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -60,8 +60,7 @@ def determine_worker_count(): num_workers = 1 return num_workers -def buildparser(): - parser = argparse.ArgumentParser(prog='meson test') +def add_arguments(parser): parser.add_argument('--repeat', default=1, dest='repeat', type=int, help='Number of times to run the tests.') parser.add_argument('--no-rebuild', default=False, action='store_true', @@ -102,7 +101,6 @@ def buildparser(): help='Arguments to pass to the specified test(s) or all tests') parser.add_argument('args', nargs='*', help='Optional list of tests to run') - return parser def returncode_to_status(retcode): @@ -737,9 +735,7 @@ def rebuild_all(wd): return True -def run(args): - options = buildparser().parse_args(args) - +def run(options): if options.benchmark: options.num_processes = 1 @@ -784,3 +780,9 @@ def run(args): else: print(e) return 1 + +def run_with_args(args): + parser = argparse.ArgumentParser(prog='meson test') + add_arguments(parser) + options = parser.parse_args(args) + return run(options) -- cgit v1.1