diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.py index 3a77241cc66..f9b88321d50 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 620badb6fb2..67d40ae7aab 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(