running without arguments prints the help

This commit is contained in:
2026-05-10 16:52:31 +02:00
parent 5a2844c7cb
commit 150cc57932
2 changed files with 19 additions and 1 deletions
+11 -1
View File
@@ -25,7 +25,8 @@ app = typer.Typer(
"- By default, Chromy uses Chroma's default persistent location behavior.\n" "- 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"- Set {CHROMA_FOLDER_ENV_VAR} to a parent directory to override it.\n"
f"- Chromy stores data in <{CHROMA_FOLDER_ENV_VAR}>/chroma." f"- Chromy stores data in <{CHROMA_FOLDER_ENV_VAR}>/chroma."
) ),
invoke_without_command=True,
) )
ExitCodeHandler = Callable[[], int] ExitCodeHandler = Callable[[], int]
@@ -46,6 +47,15 @@ def _fail(message: str) -> None:
raise typer.Exit(1) 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 # LIST COLLECTIONS
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
+8
View File
@@ -252,6 +252,14 @@ class CliTests(unittest.TestCase):
self.assertNotEqual(result.exit_code, 0) self.assertNotEqual(result.exit_code, 0)
self.assertIn("Missing option", result.output) 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: def test_cli_help_documents_chroma_folder_env_var(self) -> None:
result = _invoke(["--help"]) result = _invoke(["--help"])