Remove shell autocompletion. Closes #96

This commit is contained in:
Yiorgis Gozadinos 2025-10-13 18:00:07 +03:00
parent dae0992e3f
commit 63f0e01f60
No known key found for this signature in database
2 changed files with 3 additions and 84 deletions

View file

@ -54,16 +54,14 @@ haiku-rag add-src /mnt/data/doc1.pdf --meta source=manual --meta page_count=12 -
### Get Document
```bash
haiku-rag get <TAB>
# or
haiku-rag get 3f4a... # document ID (autocomplete supported)
haiku-rag get 3f4a... # document ID
```
### Delete Document
```bash
haiku-rag delete <TAB>
haiku-rag rm <TAB> # alias
haiku-rag delete 3f4a... # document ID
haiku-rag rm 3f4a... # alias
```
Use this when you want to change things like the embedding model or chunk size for example.
@ -212,20 +210,3 @@ This will:
- Optimize the new database for best performance
The original SQLite database remains unchanged, so you can safely migrate without risk of data loss.
## Shell Autocompletion
Enable shell autocompletion for faster, errorfree usage.
- Temporary (current shell only):
```bash
eval "$(haiku-rag --show-completion)"
```
- Permanent installation:
```bash
haiku-rag --install-completion
```
Whats completed:
- `get` and `delete`/`rm`: Document IDs from the selected database (respects `--db`).
- `add-src`: Local filesystem paths (URLs can still be typed manually).

View file

@ -16,65 +16,6 @@ cli = typer.Typer(
)
def complete_document_ids(ctx: typer.Context, incomplete: str):
"""Autocomplete document IDs from the selected DB."""
db_path = ctx.params.get("db") or (Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb")
try:
from haiku.rag.client import HaikuRAG
async def _list_ids():
async with HaikuRAG(db_path) as client:
docs = await client.list_documents()
return [d.id for d in docs if d.id]
ids = asyncio.run(_list_ids())
except Exception:
return []
return [i for i in ids if i and i.startswith(incomplete)]
def complete_local_paths(ctx: typer.Context, incomplete: str) -> list[str]:
"""Autocomplete local filesystem paths.
Provides directory/file suggestions based on the current incomplete input.
Does not validate or restrict to specific extensions to keep it flexible
(URLs are still allowed to be typed manually).
"""
try:
text = incomplete or ""
# Expand user home
from os.path import expanduser
expanded = expanduser(text)
p = Path(expanded)
# Choose directory to list and prefix to filter
if text == "" or text.endswith(("/", "\\")):
directory = p
prefix = ""
else:
directory = p.parent
prefix = p.name
if not directory.exists():
return []
suggestions: list[str] = []
for entry in directory.iterdir():
name = entry.name
if not prefix or name.startswith(prefix):
suggestion = str(directory / name)
if entry.is_dir():
suggestion += "/"
suggestions.append(suggestion)
return suggestions
except Exception:
return []
async def check_version():
"""Check if haiku.rag is up to date and show warning if not."""
up_to_date, current_version, latest_version = await is_up_to_date()
@ -191,7 +132,6 @@ def add_document_text(
def add_document_src(
source: str = typer.Argument(
help="The file path or URL of the document to add",
autocompletion=complete_local_paths,
),
title: str | None = typer.Option(
None,
@ -225,7 +165,6 @@ def add_document_src(
def get_document(
doc_id: str = typer.Argument(
help="The ID of the document to get",
autocompletion=complete_document_ids,
),
db: Path = typer.Option(
Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb",
@ -243,7 +182,6 @@ def get_document(
def delete_document(
doc_id: str = typer.Argument(
help="The ID of the document to delete",
autocompletion=complete_document_ids,
),
db: Path = typer.Option(
Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb",