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
|
2024-05-16 18:00:17 -04:00
|
|
|
from buildscripts.resmokelib.generate_fcv_constants import GenerateFCVConstantsPlugin
|
2025-08-21 17:12:11 -04:00
|
|
|
from buildscripts.resmokelib.generate_fuzz_config.plugin import GenerateFuzzConfigPlugin
|
2020-06-17 17:41:54 +03:00
|
|
|
from buildscripts.resmokelib.hang_analyzer import HangAnalyzerPlugin
|
2023-08-31 16:59:53 +00:00
|
|
|
from buildscripts.resmokelib.hang_analyzer.core_analyzer import CoreAnalyzerPlugin
|
2022-05-31 20:18:01 +00:00
|
|
|
from buildscripts.resmokelib.multiversion import MultiversionPlugin
|
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
|
2020-05-14 10:26:32 -04:00
|
|
|
|
|
|
|
|
_PLUGINS = [
|
|
|
|
|
RunPlugin(),
|
2023-08-31 16:59:53 +00:00
|
|
|
CoreAnalyzerPlugin(),
|
2020-05-14 10:26:32 -04:00
|
|
|
HangAnalyzerPlugin(),
|
2021-01-22 17:54:36 +03:00
|
|
|
PowercyclePlugin(),
|
2021-09-02 20:00:17 +00:00
|
|
|
GenerateFCVConstantsPlugin(),
|
2021-10-31 19:49:26 -04:00
|
|
|
DiscoveryPlugin(),
|
2022-05-31 20:18:01 +00:00
|
|
|
MultiversionPlugin(),
|
2023-08-02 01:56:19 +00:00
|
|
|
GenerateFuzzConfigPlugin(),
|
2020-05-14 10:26:32 -04:00
|
|
|
]
|
2015-05-08 14:20:43 -04:00
|
|
|
|
2019-03-27 22:43:28 -04:00
|
|
|
|
2023-01-25 21:03:49 +00:00
|
|
|
def get_parser(usage=None):
|
|
|
|
|
"""Get the resmoke parser."""
|
2021-02-18 17:18:35 -05:00
|
|
|
parser = argparse.ArgumentParser(usage=usage)
|
2020-04-15 13:22:09 -04:00
|
|
|
subparsers = parser.add_subparsers(dest="command")
|
2023-10-11 13:09:40 +00:00
|
|
|
parser.add_argument(
|
2024-05-16 18:00:17 -04:00
|
|
|
"--configDir",
|
|
|
|
|
dest="config_dir",
|
|
|
|
|
metavar="CONFIG_DIR",
|
|
|
|
|
help="Directory to search for resmoke configuration files",
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--jstestsDir",
|
|
|
|
|
dest="jstests_dir",
|
|
|
|
|
metavar="CONFIG_DIR",
|
|
|
|
|
help="Directory to search for jstests files existence while suite validation",
|
|
|
|
|
)
|
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
|
|
|
|
2023-01-25 21:03:49 +00:00
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
2025-07-10 12:04:10 -04:00
|
|
|
def parse(sys_args, usage=None) -> tuple[argparse.ArgumentParser, dict]:
|
2023-01-25 21:03:49 +00:00
|
|
|
"""Parse the CLI args."""
|
|
|
|
|
|
|
|
|
|
parser = get_parser(usage=usage)
|
2020-04-15 13:22:09 -04:00
|
|
|
parsed_args = parser.parse_args(sys_args)
|
|
|
|
|
|
2025-07-10 12:04:10 -04:00
|
|
|
return parser, vars(parsed_args)
|
2019-03-27 22:43:28 -04:00
|
|
|
|
2020-04-15 13:22:09 -04:00
|
|
|
|
2024-10-22 09:18:07 -04:00
|
|
|
def parse_command_line(sys_args, usage=None, should_configure_otel=True, **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
|
|
|
|
2025-07-10 12:04:10 -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:
|
2024-10-22 09:18:07 -04:00
|
|
|
subcommand_obj = plugin.parse(
|
|
|
|
|
subcommand, parser, parsed_args, should_configure_otel, **kwargs
|
|
|
|
|
)
|
2020-05-14 10:26:32 -04:00
|
|
|
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
|
|
|
|
2024-10-22 09:18:07 -04:00
|
|
|
def set_run_options(argstr="", should_configure_otel=True):
|
2020-04-15 13:22:09 -04:00
|
|
|
"""Populate the config module variables for the 'run' subcommand with the default options."""
|
2024-05-16 18:00:17 -04:00
|
|
|
parser, parsed_args = parse(["run"] + shlex.split(argstr))
|
2024-10-22 09:18:07 -04:00
|
|
|
configure_resmoke.validate_and_update_config(parser, parsed_args, should_configure_otel)
|