-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclawsqlite_cli.py
More file actions
84 lines (59 loc) · 2.49 KB
/
clawsqlite_cli.py
File metadata and controls
84 lines (59 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
"""Top-level clawsqlite CLI.
Namespaces:
- `clawsqlite knowledge ...` – knowledge base application (Markdown + SQLite)
- `clawsqlite db ...` – generic SQLite operations
- `clawsqlite index ...` – FTS / vector index operations
- `clawsqlite fs ...` – filesystem + DB helpers
- `clawsqlite embed ...` – embedding primitives (text → vector tables)
设计原则:
- 顶层只负责选择 namespace(knowledge / db / index / fs / embed),
具体子命令和参数解析完全交给各自子 CLI;
- 避免在 argparse 里复制子 parser 的 actions,
不抢占 `-h/--help` 等选项;
- `clawsqlite --help` 给出简洁的总览。
"""
from __future__ import annotations
import argparse
from typing import List, Optional
import sys
def _print_top_level_help() -> None:
parser = argparse.ArgumentParser(prog="clawsqlite", description="ClawSQLite CLI")
sub = parser.add_subparsers(dest="ns")
sub.add_parser("knowledge", help="Knowledge base application")
sub.add_parser("db", help="Low-level SQLite operations")
sub.add_parser("index", help="Index (FTS / vec) operations")
sub.add_parser("fs", help="Filesystem + DB helpers")
sub.add_parser("embed", help="Embedding primitives (text → vector tables)")
parser.print_help()
def main(argv: Optional[List[str]] = None) -> int:
import sys as _sys
if argv is None:
argv = _sys.argv[1:]
# No args or explicit help → show top-level help
if not argv or argv[0] in {"-h", "--help"}:
_print_top_level_help()
return 0
ns = argv[0]
remainder = argv[1:]
if ns == "knowledge":
from clawsqlite_knowledge.knowledge_cli import main as knowledge_main
return int(knowledge_main(remainder))
if ns == "db":
from clawsqlite_plumbing import db_cli
return int(db_cli.main(remainder))
if ns == "index":
from clawsqlite_plumbing import index_cli
return int(index_cli.main(remainder))
if ns == "fs":
from clawsqlite_plumbing import fs_cli
return int(fs_cli.main(remainder))
if ns == "embed":
from clawsqlite_plumbing import embed_cli
return int(embed_cli.main(remainder))
sys.stderr.write(f"ERROR: unknown namespace {ns!r}\n")
sys.stderr.write("NEXT: run 'clawsqlite --help' to see supported namespaces and usage.\n")
return 2
if __name__ == "__main__": # pragma: no cover
import sys as _sys
raise SystemExit(main(_sys.argv[1:]))