move top-level modules into a real package

This commit is contained in:
Matteo Rosati
2026-04-22 15:47:46 +02:00
parent e33160282c
commit 8ebab832d5
35 changed files with 6192 additions and 31 deletions
+1
View File
@@ -0,0 +1 @@
"""Command handlers package for the Chroma CLI."""
+9
View File
@@ -0,0 +1,9 @@
from argparse import Namespace
from chromy.utilities import ingest_file
def handle_add_data(args: Namespace) -> int:
records_added = ingest_file(args.collection, args.file)
print(f"Added {records_added} records to collection '{args.collection}'.")
return 0
+8
View File
@@ -0,0 +1,8 @@
from argparse import Namespace
from chromy.chroma_functions import count_collection
def handle_count_collection(args: Namespace) -> int:
print(count_collection(args.collection))
return 0
+9
View File
@@ -0,0 +1,9 @@
from argparse import Namespace
from chromy.chroma_functions import create_collection
def handle_create_collection(args: Namespace) -> int:
collection_name = create_collection(args.collection)
print(f"Created collection '{collection_name}'.")
return 0
+40
View File
@@ -0,0 +1,40 @@
from argparse import Namespace
from chromy.chroma_functions import delete_collection, delete_data
def _parse_where_clause(where_clause: str) -> dict[str, str]:
condition, separator, value = where_clause.partition("=")
if separator == "":
raise ValueError("Invalid --where value. Expected <condition>=<value>.")
condition = condition.strip()
value = value.strip()
if not condition or not value:
raise ValueError("Invalid --where value. Expected <condition>=<value>.")
return {condition: value}
def handle_delete_collection(args: Namespace) -> int:
delete_collection(args.collection)
print(f"Deleted collection '{args.collection}'.")
return 0
def handle_delete_records(args: Namespace) -> int:
try:
where = _parse_where_clause(args.where)
except ValueError as exc:
args.error_message = str(exc)
raise
deleted = delete_data(args.collection, where)
condition, value = next(iter(where.items()))
print(
f"Deleted {deleted} record(s) from collection '{args.collection}' "
f"where {condition}={value}."
)
return 0
+14
View File
@@ -0,0 +1,14 @@
from argparse import Namespace
from chromy.chroma_functions import list_collections
from chromy.utilities import print_lines
def handle_list_collections(_: Namespace) -> int:
collections = list_collections()
if not collections:
print("No collections found.")
return 0
print_lines(collections)
return 0
+9
View File
@@ -0,0 +1,9 @@
from argparse import Namespace
from chromy.utilities import format_query_result, print_lines, run_query
def handle_query(args: Namespace) -> int:
result = run_query(args.collection, args.query_text)
print_lines(format_query_result(result))
return 0