2018-03-27 14:30:46 -04:00
|
|
|
"""Parser for command line arguments."""
|
2015-05-08 14:20:43 -04:00
|
|
|
|
2020-04-15 13:22:09 -04:00
|
|
|
import argparse
|
2020-06-17 17:41:54 +03:00
|
|
|
import shlex
|
2015-05-08 14:20:43 -04:00
|
|
|
|
2020-06-17 17:41:54 +03:00
|
|
|
from buildscripts.resmokelib import configure_resmoke
|
2021-10-31 19:49:26 -04:00
|
|
|
from buildscripts.resmokelib.discovery import DiscoveryPlugin
|
|
|
|
|
from buildscripts.resmokelib.generate_fcv_constants import \
|
|
|
|
|
GenerateFCVConstantsPlugin
|
2020-06-17 17:41:54 +03:00
|
|
|
from buildscripts.resmokelib.hang_analyzer import HangAnalyzerPlugin
|
2021-01-22 17:54:36 +03:00
|
|
|
from buildscripts.resmokelib.powercycle import PowercyclePlugin
|
2020-06-17 17:41:54 +03:00
|
|
|
from buildscripts.resmokelib.run import RunPlugin
|
2021-07-20 09:07:31 -04:00
|
|
|
from buildscripts.resmokelib.symbolizer import SymbolizerPlugin
|
2020-06-17 17:41:54 +03:00
|
|
|
from buildscripts.resmokelib.undodb import UndoDbPlugin
|
2020-05-14 10:26:32 -04:00
|
|
|
|
|
|
|
|
_PLUGINS = [
|
|
|
|
|
RunPlugin(),
|
|
|
|
|
HangAnalyzerPlugin(),
|
|
|
|
|
UndoDbPlugin(),
|
2021-01-22 17:54:36 +03:00
|
|
|
PowercyclePlugin(),
|
2021-07-20 09:07:31 -04:00
|
|
|
SymbolizerPlugin(),
|
2021-09-02 20:00:17 +00:00
|
|
|
GenerateFCVConstantsPlugin(),
|
2021-10-31 19:49:26 -04:00
|
|
|
DiscoveryPlugin(),
|
2020-05-14 10:26:32 -04:00
|
|
|
]
|
2015-05-08 14:20:43 -04:00
|
|
|
|
2019-03-27 22:43:28 -04:00
|
|
|
|
2021-02-18 17:18:35 -05:00
|
|
|
def parse(sys_args, usage=None):
|
|
|
|
|
"""Parse the CLI args."""
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(usage=usage)
|
2020-04-15 13:22:09 -04:00
|
|
|
subparsers = parser.add_subparsers(dest="command")
|
2022-03-24 16:44:34 -04:00
|
|
|
parser.add_argument("--configDir", dest="config_dir", metavar="CONFIG_DIR",
|
|
|
|
|
help="Directory to search for resmoke configuration files")
|
2020-04-15 13:22:09 -04:00
|
|
|
|
|
|
|
|
# Add sub-commands.
|
2020-05-14 10:26:32 -04:00
|
|
|
for plugin in _PLUGINS:
|
|
|
|
|
plugin.add_subcommand(subparsers)
|
2020-04-15 13:22:09 -04:00
|
|
|
|
|
|
|
|
parsed_args = parser.parse_args(sys_args)
|
|
|
|
|
|
2020-11-05 14:34:10 +03:00
|
|
|
return parser, parsed_args
|
2019-03-27 22:43:28 -04:00
|
|
|
|
2020-04-15 13:22:09 -04:00
|
|
|
|
2021-02-18 17:18:35 -05:00
|
|
|
def parse_command_line(sys_args, usage=None, **kwargs):
|
2020-04-15 13:22:09 -04:00
|
|
|
"""Parse the command line arguments passed to resmoke.py and return the subcommand object to execute."""
|
2021-02-18 17:18:35 -05:00
|
|
|
parser, parsed_args = parse(sys_args, usage)
|
2020-04-15 13:22:09 -04:00
|
|
|
|
2020-05-04 12:02:26 -04:00
|
|
|
subcommand = parsed_args.command
|
2020-05-13 14:35:29 -04:00
|
|
|
|
2020-05-14 10:26:32 -04:00
|
|
|
for plugin in _PLUGINS:
|
|
|
|
|
subcommand_obj = plugin.parse(subcommand, parser, parsed_args, **kwargs)
|
|
|
|
|
if subcommand_obj is not None:
|
|
|
|
|
return subcommand_obj
|
2020-05-04 12:02:26 -04:00
|
|
|
|
2020-05-14 10:26:32 -04:00
|
|
|
raise RuntimeError(f"Resmoke configuration has invalid subcommand: {subcommand}. Try '--help'")
|
2019-03-27 22:43:28 -04:00
|
|
|
|
2017-07-21 10:21:09 -04:00
|
|
|
|
2020-04-15 13:22:09 -04:00
|
|
|
def set_run_options(argstr=''):
|
|
|
|
|
"""Populate the config module variables for the 'run' subcommand with the default options."""
|
2020-05-14 10:26:32 -04:00
|
|
|
parser, parsed_args = parse(['run'] + shlex.split(argstr))
|
2020-04-15 13:22:09 -04:00
|
|
|
configure_resmoke.validate_and_update_config(parser, parsed_args)
|