Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions otava/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ def add_service_option_groups(parser) -> None:
BigQueryConfig.add_parser_args(parser.add_argument_group('BigQuery Options', 'Options for BigQuery configuration'))


def argument_group(parser, title: str):
"""Return the existing argument group named `title` on `parser`.

Subparsers inherit the service option groups from the shared parent parser,
so options that belong to a service must be added to that service's group
instead of the parser's default group. Falls back to creating the group if
it is not present.
"""
for group in parser._action_groups:
if group.title == title:
return group
return parser.add_argument_group(title)


def create_subparser_parent() -> configargparse.ArgumentParser:
"""Create a parent parser for subparsers that accepts --config-file and service options."""
parent = configargparse.ArgumentParser(add_help=False)
Expand Down
6 changes: 3 additions & 3 deletions otava/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,17 @@ def create_otava_cli_parser() -> argparse.ArgumentParser:
parents=[subparser_parent],
)
analyze_parser.add_argument("tests", help="name of the test or group of the tests", nargs="+")
analyze_parser.add_argument(
config.argument_group(analyze_parser, "Grafana Options").add_argument(
"--update-grafana",
help="Update Grafana dashboards with appropriate annotations of change points",
action="store_true",
)
analyze_parser.add_argument(
config.argument_group(analyze_parser, "PostgreSQL Options").add_argument(
"--update-postgres",
help="Update PostgreSQL database results with change points",
action="store_true",
)
analyze_parser.add_argument(
config.argument_group(analyze_parser, "BigQuery Options").add_argument(
"--update-bigquery",
help="Update BigQuery database results with change points",
action="store_true",
Expand Down
6 changes: 3 additions & 3 deletions tests/cli_help_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ def test_otava_analyze_help_output():
-h, --help show this help message and exit
--config-file CONFIG_FILE
Otava config file path [env var: OTAVA_CONFIG]
--update-grafana Update Grafana dashboards with appropriate annotations of change points
--update-postgres Update PostgreSQL database results with change points
--update-bigquery Update BigQuery database results with change points
--notify-slack NOTIFY_SLACK [NOTIFY_SLACK ...]
Send notification containing a summary of change points to given Slack
channels
Expand Down Expand Up @@ -233,6 +230,7 @@ def test_otava_analyze_help_output():
Grafana server user [env var: GRAFANA_USER]
--grafana-password GRAFANA_PASSWORD
Grafana server password [env var: GRAFANA_PASSWORD]
--update-grafana Update Grafana dashboards with appropriate annotations of change points

Slack Options:
Options for Slack configuration
Expand All @@ -254,6 +252,7 @@ def test_otava_analyze_help_output():
PostgreSQL password [env var: POSTGRES_PASSWORD]
--postgres-database POSTGRES_DATABASE
PostgreSQL database name [env var: POSTGRES_DATABASE]
--update-postgres Update PostgreSQL database results with change points

BigQuery Options:
Options for BigQuery configuration
Expand All @@ -264,6 +263,7 @@ def test_otava_analyze_help_output():
BigQuery dataset [env var: BIGQUERY_DATASET]
--bigquery-credentials BIGQUERY_CREDENTIALS
BigQuery credentials file [env var: BIGQUERY_VAULT_SECRET]
--update-bigquery Update BigQuery database results with change points

In general, command-line values override environment variables which override defaults.
"""
Expand Down