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
9 changes: 7 additions & 2 deletions src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def is_str_dict(val: Any) -> TypeGuard[TaskParameters]:
invoke_without_command=True, context_settings={"auto_envvar_prefix": "BLUEAPI"}
)
@click.version_option(version=__version__, prog_name="blueapi")
@click.option("-H", "--host", type=str)
@click.option(
"-c", "--config", type=Path, help="Path to configuration YAML file", multiple=True
)
Expand All @@ -99,7 +100,10 @@ def is_str_dict(val: Any) -> TypeGuard[TaskParameters]:
)
@click.pass_context
def main(
ctx: click.Context, config: tuple[Path, ...], log_level: str | None = None
ctx: click.Context,
config: tuple[Path, ...],
host: str | None = None,
log_level: str | None = None,
) -> None:
# if no command is supplied, run with the options passed

Expand All @@ -111,7 +115,8 @@ def main(
config_loader.use_values_from_yaml(*config)
except FileNotFoundError as fnfe:
raise ClickException(f"Config file not found: {fnfe.filename}") from fnfe

if host:
config_loader.use_values({"api": {"url": host}})
if log_level:
config_loader.use_values({"logging": {"level": log_level}})

Expand Down
42 changes: 42 additions & 0 deletions tests/unit_tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,3 +1395,45 @@ def test_log_level_override(flag: str, level: str, runner: CliRunner):
runner.invoke(main, [flag])
mock_log.getLogger().setLevel.assert_called_once_with(level)
mock_log.StreamHandler().setLevel.assert_called_once_with(level)


@responses.activate
def test_host_option(runner: CliRunner):
response = responses.add(
responses.GET,
"http://override.example.com:5678/plans",
json={"plans": []},
status=200,
)

res = runner.invoke(
main,
["--host", "http://override.example.com:5678", "controller", "plans"],
)
assert response.call_count == 1
assert res.exit_code == 0


@responses.activate
def test_host_overrides_config(runner: CliRunner):
config_path = "tests/unit_tests/example_yaml/rest_config.yaml"
response = responses.add(
responses.GET,
"http://override.example.com:5678/plans",
json={"plans": []},
status=200,
)

res = runner.invoke(
main,
[
"--host",
"http://override.example.com:5678",
"--config",
config_path,
"controller",
"plans",
],
)
assert response.call_count == 1
assert res.exit_code == 0
Loading