Skip to content

Commit aca9070

Browse files
committed
fix: allow CLI group help without config
1 parent 5027d0c commit aca9070

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

app/connectors_service/connectors/connectors_cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def load_config(ctx, config):
4545
raise FileNotFoundError(msg)
4646

4747

48+
def is_help_request(ctx):
49+
return any(arg in ctx.help_option_names for arg in ctx.args)
50+
51+
4852
# Main group
4953
@click.group(
5054
invoke_without_command=True,
@@ -58,13 +62,15 @@ def cli(ctx, config):
5862
if ctx.invoked_subcommand is None:
5963
click.echo(ctx.get_help())
6064
return
65+
if is_help_request(ctx):
66+
return
6167

6268
ctx.ensure_object(dict)
6369
try:
6470
ctx.obj["config"] = load_config(ctx, config)
6571
except FileNotFoundError as e:
6672
click.echo(
67-
f"{e} Make sure that the config is either present at the default location ({CONFIG_FILE_PATH}) or it's passed via the '-c' or '--config' option."
73+
f"{e} Run `connectors login` first, or pass a config via the '-c' or '--config' option."
6874
)
6975
ctx.exit(1)
7076

app/connectors_service/tests/test_connectors_cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ def test_connector_help_page():
128128
assert "Commands:" in result.output
129129

130130

131+
@pytest.mark.parametrize(
132+
"commands", [["connector", "--help"], ["index", "--help"], ["job", "--help"]]
133+
)
134+
def test_group_help_page_does_not_require_config(commands, mock_cli_config):
135+
mock_cli_config.side_effect = FileNotFoundError(CONFIG_FILE_PATH)
136+
137+
runner = CliRunner()
138+
result = runner.invoke(cli, commands)
139+
140+
assert result.exit_code == 0
141+
assert "Usage:" in result.output
142+
mock_cli_config.assert_not_called()
143+
144+
131145
@patch("connectors.cli.connector.Connector.list_connectors", AsyncMock(return_value=[]))
132146
def test_connector_list_no_connectors():
133147
runner = CliRunner()

0 commit comments

Comments
 (0)