Remove shell autocompletion. Closes #96
This commit is contained in:
parent
dae0992e3f
commit
63f0e01f60
2 changed files with 3 additions and 84 deletions
25
docs/cli.md
25
docs/cli.md
|
|
@ -54,16 +54,14 @@ haiku-rag add-src /mnt/data/doc1.pdf --meta source=manual --meta page_count=12 -
|
||||||
### Get Document
|
### Get Document
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
haiku-rag get <TAB>
|
haiku-rag get 3f4a... # document ID
|
||||||
# or
|
|
||||||
haiku-rag get 3f4a... # document ID (autocomplete supported)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Delete Document
|
### Delete Document
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
haiku-rag delete <TAB>
|
haiku-rag delete 3f4a... # document ID
|
||||||
haiku-rag rm <TAB> # alias
|
haiku-rag rm 3f4a... # alias
|
||||||
```
|
```
|
||||||
|
|
||||||
Use this when you want to change things like the embedding model or chunk size for example.
|
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
|
- Optimize the new database for best performance
|
||||||
|
|
||||||
The original SQLite database remains unchanged, so you can safely migrate without risk of data loss.
|
The original SQLite database remains unchanged, so you can safely migrate without risk of data loss.
|
||||||
|
|
||||||
## Shell Autocompletion
|
|
||||||
|
|
||||||
Enable shell autocompletion for faster, error‑free usage.
|
|
||||||
|
|
||||||
- Temporary (current shell only):
|
|
||||||
```bash
|
|
||||||
eval "$(haiku-rag --show-completion)"
|
|
||||||
```
|
|
||||||
- Permanent installation:
|
|
||||||
```bash
|
|
||||||
haiku-rag --install-completion
|
|
||||||
```
|
|
||||||
|
|
||||||
What’s completed:
|
|
||||||
- `get` and `delete`/`rm`: Document IDs from the selected database (respects `--db`).
|
|
||||||
- `add-src`: Local filesystem paths (URLs can still be typed manually).
|
|
||||||
|
|
|
||||||
|
|
@ -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():
|
async def check_version():
|
||||||
"""Check if haiku.rag is up to date and show warning if not."""
|
"""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()
|
up_to_date, current_version, latest_version = await is_up_to_date()
|
||||||
|
|
@ -191,7 +132,6 @@ def add_document_text(
|
||||||
def add_document_src(
|
def add_document_src(
|
||||||
source: str = typer.Argument(
|
source: str = typer.Argument(
|
||||||
help="The file path or URL of the document to add",
|
help="The file path or URL of the document to add",
|
||||||
autocompletion=complete_local_paths,
|
|
||||||
),
|
),
|
||||||
title: str | None = typer.Option(
|
title: str | None = typer.Option(
|
||||||
None,
|
None,
|
||||||
|
|
@ -225,7 +165,6 @@ def add_document_src(
|
||||||
def get_document(
|
def get_document(
|
||||||
doc_id: str = typer.Argument(
|
doc_id: str = typer.Argument(
|
||||||
help="The ID of the document to get",
|
help="The ID of the document to get",
|
||||||
autocompletion=complete_document_ids,
|
|
||||||
),
|
),
|
||||||
db: Path = typer.Option(
|
db: Path = typer.Option(
|
||||||
Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb",
|
Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb",
|
||||||
|
|
@ -243,7 +182,6 @@ def get_document(
|
||||||
def delete_document(
|
def delete_document(
|
||||||
doc_id: str = typer.Argument(
|
doc_id: str = typer.Argument(
|
||||||
help="The ID of the document to delete",
|
help="The ID of the document to delete",
|
||||||
autocompletion=complete_document_ids,
|
|
||||||
),
|
),
|
||||||
db: Path = typer.Option(
|
db: Path = typer.Option(
|
||||||
Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb",
|
Config.DEFAULT_DATA_DIR / "haiku.rag.lancedb",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue