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 ## Commands
```text ```text
list-collections | lc list-collections
create-collection | cc <collection> create-collection <collection>
delete-collection | dc <collection> delete-collection <collection>
count | co <collection> count <collection>
add-data | ad <collection> <file> add-data <collection> <file>
query | q <collection> <query_text> query <collection> <query_text>
delete | del <collection> --where <condition>=<value> delete <collection> --where <condition>=<value>
``` ```
### Examples ### Examples
-10
View File
@@ -31,7 +31,6 @@ def _fail(message: str) -> None:
raise typer.Exit(1) raise typer.Exit(1)
@app.command("lc", help="List all collections stored in the local Chroma database.")
@app.command( @app.command(
"list-collections", "list-collections",
help="List all collections stored in the local Chroma database.", help="List all collections stored in the local Chroma database.",
@@ -40,7 +39,6 @@ def list_collections() -> None:
_run(handle_list_collections) _run(handle_list_collections)
@app.command("cc", help="Create a collection in the local Chroma database.")
@app.command( @app.command(
"create-collection", "create-collection",
help="Create a collection in the local Chroma database.", help="Create a collection in the local Chroma database.",
@@ -57,7 +55,6 @@ def create_collection(
_fail(f"Collection '{collection}' already exists.") _fail(f"Collection '{collection}' already exists.")
@app.command("dc", help="Delete a collection from the local Chroma database.")
@app.command( @app.command(
"delete-collection", "delete-collection",
help="Delete a collection from the local Chroma database.", help="Delete a collection from the local Chroma database.",
@@ -74,7 +71,6 @@ def delete_collection(
_fail(f"Collection '{collection}' does not exist.") _fail(f"Collection '{collection}' does not exist.")
@app.command("co", help="Count records in a collection from the local Chroma database.")
@app.command( @app.command(
"count", "count",
help="Count records in a collection from the local Chroma database.", help="Count records in a collection from the local Chroma database.",
@@ -91,10 +87,6 @@ def count(
_fail(f"Collection '{collection}' does not exist.") _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( @app.command(
"add-data", "add-data",
help="Chunk, embed, and add a file to a collection in the local Chroma database.", 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.") _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.") @app.command("query", help="Query a collection with the provided text.")
def query( def query(
collection: Annotated[ collection: Annotated[
@@ -135,7 +126,6 @@ def query(
_fail(f"Collection '{collection}' does not exist.") _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.") @app.command("delete", help="Delete records from a collection using a metadata filter.")
def delete_records( def delete_records(
collection: Annotated[ collection: Annotated[
+21 -24
View File
@@ -11,92 +11,83 @@ from chromy.cli import app
class CliTests(unittest.TestCase): class CliTests(unittest.TestCase):
def test_list_collections_and_alias(self) -> None: def test_list_collections(self) -> None:
for command in ("list-collections", "lc"):
with patch( with patch(
"chromy.handlers.list_collections.list_collections", "chromy.handlers.list_collections.list_collections",
return_value=[], return_value=[],
): ):
result = _invoke([command]) result = _invoke(["list-collections"])
self.assertEqual(result.exit_code, 0) self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "No collections found.\n") self.assertEqual(result.stdout, "No collections found.\n")
def test_create_collection_and_alias(self) -> None: def test_create_collection(self) -> None:
for command in ("create-collection", "cc"):
with patch( with patch(
"chromy.handlers.create_collection.create_collection", "chromy.handlers.create_collection.create_collection",
return_value="notes", return_value="notes",
) as create_collection: ) as create_collection:
result = _invoke([command, "notes"]) result = _invoke(["create-collection", "notes"])
create_collection.assert_called_once_with("notes") create_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 0) self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Created collection 'notes'.\n") self.assertEqual(result.stdout, "Created collection 'notes'.\n")
def test_delete_collection_and_alias(self) -> None: def test_delete_collection(self) -> None:
for command in ("delete-collection", "dc"):
with patch( with patch(
"chromy.handlers.delete_collection.delete_collection", "chromy.handlers.delete_collection.delete_collection",
) as delete_collection: ) as delete_collection:
result = _invoke([command, "notes"]) result = _invoke(["delete-collection", "notes"])
delete_collection.assert_called_once_with("notes") delete_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 0) self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Deleted collection 'notes'.\n") self.assertEqual(result.stdout, "Deleted collection 'notes'.\n")
def test_count_and_alias(self) -> None: def test_count(self) -> None:
for command in ("count", "co"):
with patch( with patch(
"chromy.handlers.count_collection.count_collection", "chromy.handlers.count_collection.count_collection",
return_value=7, return_value=7,
) as count_collection: ) as count_collection:
result = _invoke([command, "notes"]) result = _invoke(["count", "notes"])
count_collection.assert_called_once_with("notes") count_collection.assert_called_once_with("notes")
self.assertEqual(result.exit_code, 0) self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "7\n") self.assertEqual(result.stdout, "7\n")
def test_add_data_and_alias(self) -> None: def test_add_data(self) -> None:
for command in ("add-data", "ad"):
with patch( with patch(
"chromy.handlers.add_data.ingest_file", "chromy.handlers.add_data.ingest_file",
return_value=3, return_value=3,
) as ingest_file: ) as ingest_file:
result = _invoke([command, "notes", "romeo_and_juliet.txt"]) result = _invoke(["add-data", "notes", "romeo_and_juliet.txt"])
ingest_file.assert_called_once_with("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.exit_code, 0)
self.assertEqual(result.stdout, "Added 3 records to collection 'notes'.\n") 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"]]} query_result = {"ids": [["1"]], "documents": [["hello"]]}
for command in ("query", "q"):
with ( with (
patch( patch("chromy.handlers.query.run_query", return_value=query_result) as run,
"chromy.handlers.query.run_query", return_value=query_result
) as run,
patch( patch(
"chromy.handlers.query.format_query_result", "chromy.handlers.query.format_query_result",
return_value=["Query results:", "1"], return_value=["Query results:", "1"],
) as format_result, ) as format_result,
): ):
result = _invoke([command, "notes", "Where is Romeo?"]) result = _invoke(["query", "notes", "Where is Romeo?"])
run.assert_called_once_with("notes", "Where is Romeo?") run.assert_called_once_with("notes", "Where is Romeo?")
format_result.assert_called_once_with(query_result) format_result.assert_called_once_with(query_result)
self.assertEqual(result.exit_code, 0) self.assertEqual(result.exit_code, 0)
self.assertEqual(result.stdout, "Query results:\n1\n") self.assertEqual(result.stdout, "Query results:\n1\n")
def test_delete_records_and_alias(self) -> None: def test_delete_records(self) -> None:
for command in ("delete", "del"):
with patch( with patch(
"chromy.handlers.delete_collection.delete_data", "chromy.handlers.delete_collection.delete_data",
return_value=2, return_value=2,
) as delete_data: ) as delete_data:
result = _invoke( result = _invoke(
[command, "notes", "--where", " file_name = play.txt "], ["delete", "notes", "--where", " file_name = play.txt "],
) )
delete_data.assert_called_once_with("notes", {"file_name": "play.txt"}) delete_data.assert_called_once_with("notes", {"file_name": "play.txt"})
@@ -107,6 +98,12 @@ class CliTests(unittest.TestCase):
"where file_name=play.txt.\n", "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: def test_invalid_delete_filter_keeps_user_facing_error(self) -> None:
result = _invoke(["delete", "notes", "--where", "file_name"]) result = _invoke(["delete", "notes", "--where", "file_name"])