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
5 changes: 4 additions & 1 deletion src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ 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
)
@click.pass_context
def main(ctx: click.Context, config: tuple[Path, ...]) -> None:
def main(ctx: click.Context, config: tuple[Path, ...], host: str | None):
# if no command is supplied, run with the options passed

# Set umask to DLS standard
Expand All @@ -95,6 +96,8 @@ def main(ctx: click.Context, config: tuple[Path, ...]) -> None:
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}})

loaded_config: ApplicationConfig = config_loader.load()

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 @@ -1384,3 +1384,45 @@ def test_config_schema(
def test_task_parameter_type(value, result):
t = ParametersType()
assert t.convert(value, None, None) == result


@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