Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Ensure return code non-zero on cli error (#3499)

Hal Wine1d6429853595
diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.py
index 3a77241cc6..f9b88321d5 100644
--- a/marimo/_cli/cli.py
+++ b/marimo/_cli/cli.py
@@ -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)"',
@@ -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
diff --git a/tests/_cli/test_cli.py b/tests/_cli/test_cli.py
index 620badb6fb..67d40ae7aa 100644
--- a/tests/_cli/test_cli.py
+++ b/tests/_cli/test_cli.py
@@ -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(