From 150cc57932b39c62e5e724592b2496f51a9acf71 Mon Sep 17 00:00:00 2001 From: Matteo Rosati Date: Sun, 10 May 2026 16:52:31 +0200 Subject: [PATCH] running without arguments prints the help --- chromy/cli.py | 12 +++++++++++- tests/test_cli.py | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/chromy/cli.py b/chromy/cli.py index 00358ab..aa090b7 100644 --- a/chromy/cli.py +++ b/chromy/cli.py @@ -25,7 +25,8 @@ app = typer.Typer( "- By default, Chromy uses Chroma's default persistent location behavior.\n" f"- Set {CHROMA_FOLDER_ENV_VAR} to a parent directory to override it.\n" f"- Chromy stores data in <{CHROMA_FOLDER_ENV_VAR}>/chroma." - ) + ), + invoke_without_command=True, ) ExitCodeHandler = Callable[[], int] @@ -46,6 +47,15 @@ def _fail(message: str) -> None: raise typer.Exit(1) +@app.callback() +def main(ctx: typer.Context) -> None: + """Run the CLI and show help when no command is provided.""" + if ctx.invoked_subcommand is None: + print("[bold red]Error[/]: Missing command.") + typer.echo(ctx.get_help()) + raise typer.Exit(1) + + # ------------------------------------------------------------------------------ # LIST COLLECTIONS # ------------------------------------------------------------------------------ diff --git a/tests/test_cli.py b/tests/test_cli.py index 4b34204..668a611 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -252,6 +252,14 @@ class CliTests(unittest.TestCase): self.assertNotEqual(result.exit_code, 0) self.assertIn("Missing option", result.output) + def test_cli_without_arguments_prints_error_and_help(self) -> None: + result = _invoke([]) + + self.assertEqual(result.exit_code, 1) + self.assertIn("Error: Missing command.", result.stdout) + self.assertIn("Usage:", result.stdout) + self.assertIn("Commands", result.stdout) + def test_cli_help_documents_chroma_folder_env_var(self) -> None: result = _invoke(["--help"])