Hide -p/--path in favor of standard -d/--database, closes #857

Spotted while working on #853
This commit is contained in:
Simon Willison 2025-03-28 00:10:58 -07:00
parent 945f14e120
commit 7e7ccdc19a
3 changed files with 46 additions and 11 deletions

View file

@ -300,7 +300,7 @@ Usage: llm logs list [OPTIONS]
Options:
-n, --count INTEGER Number of entries to show - defaults to 3, use 0
for all
-p, --path FILE Path to log database
-d, --database FILE Path to log database
-m, --model TEXT Filter by model or model alias
-q, --query TEXT Search for logs matching this string
--schema TEXT JSON schema, filepath or ID
@ -542,10 +542,10 @@ Usage: llm schemas list [OPTIONS]
List stored schemas
Options:
-p, --path FILE Path to log database
-q, --query TEXT Search for schemas matching this string
--full Output full schema contents
--help Show this message and exit.
-d, --database FILE Path to log database
-q, --query TEXT Search for schemas matching this string
--full Output full schema contents
--help Show this message and exit.
```
(help-schemas-show)=
@ -556,8 +556,8 @@ Usage: llm schemas show [OPTIONS] SCHEMA_ID
Show a stored schema
Options:
-p, --path FILE Path to log database
--help Show this message and exit.
-d, --database FILE Path to log database
--help Show this message and exit.
```
(help-schemas-dsl)=

View file

@ -981,6 +981,13 @@ order by prompt_attachments."order"
"--path",
type=click.Path(readable=True, exists=True, dir_okay=False),
help="Path to log database",
hidden=True,
)
@click.option(
"-d",
"--database",
type=click.Path(readable=True, exists=True, dir_okay=False),
help="Path to log database",
)
@click.option("-m", "--model", help="Filter by model or model alias")
@click.option("-q", "--query", help="Search for logs matching this string")
@ -1036,6 +1043,7 @@ order by prompt_attachments."order"
def logs_list(
count,
path,
database,
model,
query,
schema_input,
@ -1057,6 +1065,8 @@ def logs_list(
json_output,
):
"Show recent logged prompts and their responses"
if database and not path:
path = database
path = pathlib.Path(path or logs_db_path())
if not path.exists():
raise click.ClickException("No log database found at {}".format(path))
@ -1562,6 +1572,13 @@ def schemas():
"--path",
type=click.Path(readable=True, exists=True, dir_okay=False),
help="Path to log database",
hidden=True,
)
@click.option(
"-d",
"--database",
type=click.Path(readable=True, exists=True, dir_okay=False),
help="Path to log database",
)
@click.option(
"queries",
@ -1571,8 +1588,10 @@ def schemas():
help="Search for schemas matching this string",
)
@click.option("--full", is_flag=True, help="Output full schema contents")
def schemas_list(path, queries, full):
def schemas_list(path, database, queries, full):
"List stored schemas"
if database and not path:
path = database
path = pathlib.Path(path or logs_db_path())
if not path.exists():
raise click.ClickException("No log database found at {}".format(path))
@ -1633,9 +1652,18 @@ def schemas_list(path, queries, full):
"--path",
type=click.Path(readable=True, exists=True, dir_okay=False),
help="Path to log database",
hidden=True,
)
def schemas_show(schema_id, path):
@click.option(
"-d",
"--database",
type=click.Path(readable=True, exists=True, dir_okay=False),
help="Path to log database",
)
def schemas_show(schema_id, path, database):
"Show a stored schema"
if database and not path:
path = database
path = pathlib.Path(path or logs_db_path())
if not path.exists():
raise click.ClickException("No log database found at {}".format(path))

View file

@ -250,8 +250,11 @@ def test_logs_path(monkeypatch, env, user_path):
@pytest.mark.parametrize("model", ("davinci", "curie"))
def test_logs_filtered(user_path, model):
@pytest.mark.parametrize("path_option", (None, "-p", "--path", "-d", "--database"))
def test_logs_filtered(user_path, model, path_option):
log_path = str(user_path / "logs.db")
if path_option:
log_path = str(user_path / "logs_alternative.db")
db = sqlite_utils.Database(log_path)
migrate(db)
db["responses"].insert_all(
@ -265,7 +268,11 @@ def test_logs_filtered(user_path, model):
for i in range(100)
)
runner = CliRunner()
result = runner.invoke(cli, ["logs", "list", "-m", model, "--json"])
result = runner.invoke(
cli,
["logs", "list", "-m", model, "--json"]
+ ([path_option, log_path] if path_option else []),
)
assert result.exit_code == 0
records = json.loads(result.output.strip())
assert all(record["model"] == model for record in records)