remove command aliases

This commit is contained in:
Matteo Rosati
2026-04-22 22:21:14 +02:00
parent b52952a2eb
commit 0441bcd911
3 changed files with 84 additions and 97 deletions
+7 -7
View File
@@ -116,13 +116,13 @@ uv run mypy .
## Commands
```text
list-collections | lc
create-collection | cc <collection>
delete-collection | dc <collection>
count | co <collection>
add-data | ad <collection> <file>
query | q <collection> <query_text>
delete | del <collection> --where <condition>=<value>
list-collections
create-collection <collection>
delete-collection <collection>
count <collection>
add-data <collection> <file>
query <collection> <query_text>
delete <collection> --where <condition>=<value>
```
### Examples
-10
View File
@@ -31,7 +31,6 @@ def _fail(message: str) -> None:
raise typer.Exit(1)
@app.command("lc", help="List all collections stored in the local Chroma database.")
@app.command(
"list-collections",
help="List all collections stored in the local Chroma database.",
@@ -40,7 +39,6 @@ def list_collections() -> None:
_run(handle_list_collections)
@app.command("cc", help="Create a collection in the local Chroma database.")
@app.command(
"create-collection",
help="Create a collection in the local Chroma database.",
@@ -57,7 +55,6 @@ def create_collection(
_fail(f"Collection '{collection}' already exists.")
@app.command("dc", help="Delete a collection from the local Chroma database.")
@app.command(
"delete-collection",
help="Delete a collection from the local Chroma database.",
@@ -74,7 +71,6 @@ def delete_collection(
_fail(f"Collection '{collection}' does not exist.")
@app.command("co", help="Count records in a collection from the local Chroma database.")
@app.command(
"count",
help="Count records in a collection from the local Chroma database.",
@@ -91,10 +87,6 @@ def count(
_fail(f"Collection '{collection}' does not exist.")
@app.command(
"ad",
help="Chunk, embed, and add a file to a collection in the local Chroma database.",
)
@app.command(
"add-data",
help="Chunk, embed, and add a file to a collection in the local Chroma database.",
@@ -117,7 +109,6 @@ def add_data(
_fail(f"The file {file} was not found.")
@app.command("q", help="Query a collection with the provided text.")
@app.command("query", help="Query a collection with the provided text.")
def query(
collection: Annotated[
@@ -135,7 +126,6 @@ def query(
_fail(f"Collection '{collection}' does not exist.")
@app.command("del", help="Delete records from a collection using a metadata filter.")
@app.command("delete", help="Delete records from a collection using a metadata filter.")
def delete_records(
collection: Annotated[
+77 -80
View File
@@ -11,102 +11,99 @@ from chromy.cli import app
class CliTests(unittest.TestCase):
def test_list_collections_and_alias(self) -> None:
for command in ("list-collections", "lc"):
with patch(
"chromy.handlers.list_collections.list_collections",
return_value=[],
):
result = _invoke([command])
def test_list_collections(self) -> None:
with patch(
"chromy.handlers.list_collections.list_collections",
return_value=[],
):
result = _invoke(["list-collections"])
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "No collections found.\n")
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "No collections found.\n")
def test_create_collection_and_alias(self) -> None:
for command in ("create-collection", "cc"):
with patch(
"chromy.handlers.create_collection.create_collection",
return_value="notes",
) as create_collection:
result = _invoke([command, "notes"])
def test_create_collection(self) -> None:
with patch(
"chromy.handlers.create_collection.create_collection",
return_value="notes",
) as create_collection:
result = _invoke(["create-collection", "notes"])
create_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Created collection 'notes'.\n")
create_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Created collection 'notes'.\n")
def test_delete_collection_and_alias(self) -> None:
for command in ("delete-collection", "dc"):
with patch(
"chromy.handlers.delete_collection.delete_collection",
) as delete_collection:
result = _invoke([command, "notes"])
def test_delete_collection(self) -> None:
with patch(
"chromy.handlers.delete_collection.delete_collection",
) as delete_collection:
result = _invoke(["delete-collection", "notes"])
delete_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Deleted collection 'notes'.\n")
delete_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Deleted collection 'notes'.\n")
def test_count_and_alias(self) -> None:
for command in ("count", "co"):
with patch(
"chromy.handlers.count_collection.count_collection",
return_value=7,
) as count_collection:
result = _invoke([command, "notes"])
def test_count(self) -> None:
with patch(
"chromy.handlers.count_collection.count_collection",
return_value=7,
) as count_collection:
result = _invoke(["count", "notes"])
count_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "7\n")
count_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "7\n")
def test_add_data_and_alias(self) -> None:
for command in ("add-data", "ad"):
with patch(
"chromy.handlers.add_data.ingest_file",
return_value=3,
) as ingest_file:
result = _invoke([command, "notes", "romeo_and_juliet.txt"])
def test_add_data(self) -> None:
with patch(
"chromy.handlers.add_data.ingest_file",
return_value=3,
) as ingest_file:
result = _invoke(["add-data", "notes", "romeo_and_juliet.txt"])
ingest_file.assert_called_once_with("notes", "romeo_and_juliet.txt")
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Added 3 records to collection 'notes'.\n")
ingest_file.assert_called_once_with("notes", "romeo_and_juliet.txt")
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Added 3 records to collection 'notes'.\n")
def test_query_and_alias(self) -> None:
def test_query(self) -> None:
query_result = {"ids": [["1"]], "documents": [["hello"]]}
for command in ("query", "q"):
with (
patch(
"chromy.handlers.query.run_query", return_value=query_result
) as run,
patch(
"chromy.handlers.query.format_query_result",
return_value=["Query results:", "1"],
) as format_result,
):
result = _invoke([command, "notes", "Where is Romeo?"])
with (
patch("chromy.handlers.query.run_query", return_value=query_result) as run,
patch(
"chromy.handlers.query.format_query_result",
return_value=["Query results:", "1"],
) as format_result,
):
result = _invoke(["query", "notes", "Where is Romeo?"])
run.assert_called_once_with("notes", "Where is Romeo?")
format_result.assert_called_once_with(query_result)
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Query results:\n1\n")
run.assert_called_once_with("notes", "Where is Romeo?")
format_result.assert_called_once_with(query_result)
self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Query results:\n1\n")
def test_delete_records_and_alias(self) -> None:
for command in ("delete", "del"):
with patch(
"chromy.handlers.delete_collection.delete_data",
return_value=2,
) as delete_data:
result = _invoke(
[command, "notes", "--where", " file_name = play.txt "],
)
delete_data.assert_called_once_with("notes", {"file_name": "play.txt"})
self.assertEqual(result.exit_code, 0)
self.assertEqual(
result.stdout,
"Deleted 2 record(s) from collection 'notes' "
"where file_name=play.txt.\n",
def test_delete_records(self) -> None:
with patch(
"chromy.handlers.delete_collection.delete_data",
return_value=2,
) as delete_data:
result = _invoke(
["delete", "notes", "--where", " file_name = play.txt "],
)
delete_data.assert_called_once_with("notes", {"file_name": "play.txt"})
self.assertEqual(result.exit_code, 0)
self.assertEqual(
result.stdout,
"Deleted 2 record(s) from collection 'notes' "
"where file_name=play.txt.\n",
)
def test_removed_alias_is_rejected(self) -> None:
result = _invoke(["lc"])
self.assertNotEqual(result.exit_code, 0)
self.assertIn("No such command", result.output)
def test_invalid_delete_filter_keeps_user_facing_error(self) -> None:
result = _invoke(["delete", "notes", "--where", "file_name"])