From 0cd9333054b905f54270f6b8377b7c9d8b3f3e77 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 19 Aug 2023 21:48:20 -0700 Subject: [PATCH] llm aliases defaults to llm aliases list, refs #154 Refs #167 --- docs/help.md | 2 +- llm/cli.py | 6 +++++- tests/test_aliases.py | 10 ++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/help.md b/docs/help.md index 12767f0..2f33331 100644 --- a/docs/help.md +++ b/docs/help.md @@ -287,7 +287,7 @@ Options: --help Show this message and exit. Commands: - list List current aliases + list* List current aliases path Output the path to the aliases.json file remove Remove an alias set Set an alias for a model diff --git a/llm/cli.py b/llm/cli.py index 6a9af8d..996346f 100644 --- a/llm/cli.py +++ b/llm/cli.py @@ -674,7 +674,11 @@ def templates_list(): click.echo(display_truncated(text)) -@cli.group() +@cli.group( + cls=DefaultGroup, + default="list", + default_if_no_args=True, +) def aliases(): "Manage model aliases" diff --git a/tests/test_aliases.py b/tests/test_aliases.py index 4a991cf..6c256b5 100644 --- a/tests/test_aliases.py +++ b/tests/test_aliases.py @@ -4,9 +4,10 @@ import json import pytest -def test_aliases_list(): +@pytest.mark.parametrize("args", (["aliases", "list"], ["aliases"])) +def test_aliases_list(args): runner = CliRunner() - result = runner.invoke(cli, ["aliases", "list"]) + result = runner.invoke(cli, args) assert result.exit_code == 0 assert result.output == ( "3.5 : gpt-3.5-turbo\n" @@ -19,9 +20,10 @@ def test_aliases_list(): ) -def test_aliases_list_json(): +@pytest.mark.parametrize("args", (["aliases", "list"], ["aliases"])) +def test_aliases_list_json(args): runner = CliRunner() - result = runner.invoke(cli, ["aliases", "list", "--json"]) + result = runner.invoke(cli, args + ["--json"]) assert result.exit_code == 0 assert json.loads(result.output) == { "3.5": "gpt-3.5-turbo",