running without arguments prints the help
This commit is contained in:
+11
-1
@@ -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
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
@@ -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"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user