2026-04-21 14:32:10 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from chromadb.errors import NotFoundError, InternalError
|
2026-04-21 14:45:01 +02:00
|
|
|
from chroma_functions import (
|
|
|
|
|
count_collection,
|
|
|
|
|
create_collection,
|
|
|
|
|
delete_collection,
|
|
|
|
|
list_collections,
|
|
|
|
|
)
|
2026-04-21 14:32:10 +02:00
|
|
|
|
|
|
|
|
from cli_parser import build_parser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> int:
|
|
|
|
|
args = build_parser().parse_args()
|
|
|
|
|
|
|
|
|
|
if args.command in {"list-collections", "lc"}:
|
|
|
|
|
collections = list_collections()
|
|
|
|
|
if not collections:
|
|
|
|
|
print("No collections found.")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
for name in collections:
|
|
|
|
|
print(name)
|
2026-04-21 14:45:01 +02:00
|
|
|
|
2026-04-21 14:32:10 +02:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
if args.command in {"create-collection", "cc"}:
|
|
|
|
|
try:
|
2026-04-21 14:45:01 +02:00
|
|
|
collection = create_collection(args.name)
|
2026-04-21 14:32:10 +02:00
|
|
|
except InternalError:
|
|
|
|
|
print(f"Collection '{args.name}' already exists.")
|
|
|
|
|
return 1
|
|
|
|
|
|
2026-04-21 14:45:01 +02:00
|
|
|
print(f"Created collection '{collection}'.")
|
|
|
|
|
|
2026-04-21 14:32:10 +02:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
if args.command in {"delete-collection", "dc"}:
|
|
|
|
|
try:
|
|
|
|
|
delete_collection(args.name)
|
|
|
|
|
except NotFoundError:
|
|
|
|
|
print(f"Collection '{args.name}' does not exist.")
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
print(f"Deleted collection '{args.name}'.")
|
2026-04-21 14:45:01 +02:00
|
|
|
|
2026-04-21 14:32:10 +02:00
|
|
|
return 0
|
|
|
|
|
|
2026-04-21 14:45:01 +02:00
|
|
|
if args.command in {"count", "co"}:
|
|
|
|
|
try:
|
|
|
|
|
count = count_collection(args.name)
|
|
|
|
|
except NotFoundError:
|
|
|
|
|
print(f"Collection '{args.name}' does not exist.")
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
print(count)
|
|
|
|
|
|
|
|
|
|
return 0
|
2026-04-21 14:32:10 +02:00
|
|
|
|
|
|
|
|
print("Nothing to do. Use -h to see available commands.")
|
2026-04-21 14:45:01 +02:00
|
|
|
|
2026-04-21 14:32:10 +02:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
raise SystemExit(main())
|