Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure return code non-zero on cli error #3499

Merged
merged 1 commit into from
Jan 18, 2025
Merged
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
12 changes: 5 additions & 7 deletions marimo/_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,20 +789,19 @@ def env() -> None:


@main.command(
help="Install shell completions for marimo. Supports bash, zsh, fish, and elvish."
help="Install shell completions for marimo. Supports bash, zsh, and fish."
)
def shell_completion() -> None:
shell = os.environ.get("SHELL", "")
if not shell:
click.echo(
raise click.UsageError(
"Could not determine shell. Please set $SHELL environment variable.",
err=True,
)
return

# in case we're on a windows system, use .stem to remove extension
shell_name = Path(shell).stem

# N.B. change the help message above when changing supported shells
commands = {
"bash": (
'eval "$(_MARIMO_COMPLETE=bash_source marimo)"',
Expand All @@ -820,9 +819,8 @@ def shell_completion() -> None:

if shell_name not in commands:
supported = ", ".join(commands.keys())
click.echo(
f"Unsupported shell: {shell_name}. Supported shells: {supported}",
err=True,
raise click.UsageError(
f"Unsupported shell: {shell_name} (from $SHELL). Supported shells: {supported}",
)
return

Expand Down
4 changes: 2 additions & 2 deletions tests/_cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,8 @@ def test_cli_run_sandbox_prompt_yes() -> None:
),
),
# invalid shell values, rc of 0, data only on stderr
# (N.B. rc will become 2 when Issue #3476 is fixed)
("bogus", 0, False, True),
("bogus", 2, False, True),
("", 2, False, True), # usage error displayed
],
)
def test_shell_completion(
Expand Down
Loading