Skip to content

Commit 77c1435

Browse files
fix(cli): add per-subcommand -h/--help support and show model in ask output
Previously `kb ask -h` treated `-h` as the query. Now all subcommands recognize -h/--help flags. Also displays the chat model name in ask output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dfacdfd commit 77c1435

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "kb"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
description = "CLI knowledge base: index markdown + PDFs, hybrid search, RAG answers. Powered by sqlite-vec."
55
readme = "README.md"
66
license = "MIT"

src/kb/cli.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ def cmd_ask(question: str, cfg: Config, top_k: int = 8):
432432
print(
433433
f"(embed: {embed_ms:.0f}ms | search: {vec_ms + fts_ms:.1f}ms | generate: {gen_ms:.0f}ms)"
434434
)
435+
print(f"(model: {cfg.chat_model})")
435436
print(f"(tokens: {tokens.prompt_tokens} in / {tokens.completion_tokens} out)")
436437
print(f"(results: {len(results)} retrieved, {len(filtered)} above threshold)\n")
437438
print(answer)
@@ -845,14 +846,17 @@ def main():
845846
sys.exit(0)
846847

847848
if cmd == "init":
849+
if len(args) > 1 and args[1] in ("-h", "--help"):
850+
print("Usage: kb init [--project]")
851+
sys.exit(0)
848852
project = "--project" in args[1:]
849853
cmd_init(project)
850854
sys.exit(0)
851855

852856
if cmd == "completion":
853-
if len(args) < 2:
857+
if len(args) < 2 or args[1] in ("-h", "--help"):
854858
print("Usage: kb completion <zsh|bash|fish>")
855-
sys.exit(1)
859+
sys.exit(0 if len(args) > 1 and args[1] in ("-h", "--help") else 1)
856860
cmd_completion(args[1])
857861
sys.exit(0)
858862

@@ -863,57 +867,87 @@ def main():
863867
if cfg.config_path:
864868
print(f"Config: {cfg.config_path} {scope_label}")
865869

870+
# Per-subcommand help
871+
sub_help = len(args) > 1 and args[1] in ("-h", "--help")
872+
866873
if cmd == "add":
867874
if not cfg.config_path:
868875
print("No config found. Run 'kb init' first.")
869876
sys.exit(1)
877+
if sub_help or not args[1:]:
878+
print("Usage: kb add <dir> [dir...]")
879+
sys.exit(0)
870880
cmd_add(cfg, args[1:])
871881
elif cmd == "allow":
882+
if sub_help or not args[1:]:
883+
print("Usage: kb allow <file>")
884+
sys.exit(0)
872885
cmd_allow(cfg, args[1:])
873886
elif cmd == "remove":
874887
if not cfg.config_path:
875888
print("No config found. Run 'kb init' first.")
876889
sys.exit(1)
890+
if sub_help or not args[1:]:
891+
print("Usage: kb remove <dir> [dir...]")
892+
sys.exit(0)
877893
cmd_remove(cfg, args[1:])
878894
elif cmd == "sources":
895+
if sub_help:
896+
print("Usage: kb sources")
897+
sys.exit(0)
879898
cmd_sources(cfg)
880899
elif cmd == "index":
900+
if sub_help:
901+
print("Usage: kb index [DIR...] [--no-size-limit]")
902+
sys.exit(0)
881903
cmd_index(cfg, args[1:])
882904
elif cmd == "search":
883-
if len(args) < 2:
884-
print('Usage: kb search "query"')
885-
sys.exit(1)
905+
if len(args) < 2 or sub_help:
906+
print('Usage: kb search "query" [k]')
907+
sys.exit(0 if sub_help else 1)
886908
top_k = int(args[2]) if len(args) > 2 else 5
887909
cmd_search(args[1], cfg, top_k)
888910
elif cmd == "ask":
889-
if len(args) < 2:
890-
print('Usage: kb ask "question"')
891-
sys.exit(1)
911+
if len(args) < 2 or sub_help:
912+
print('Usage: kb ask "question" [k]')
913+
sys.exit(0 if sub_help else 1)
892914
top_k = int(args[2]) if len(args) > 2 else 8
893915
cmd_ask(args[1], cfg, top_k)
894916
elif cmd == "similar":
895-
if len(args) < 2:
917+
if len(args) < 2 or sub_help:
896918
print("Usage: kb similar <file> [k]")
897-
sys.exit(1)
919+
sys.exit(0 if sub_help else 1)
898920
top_k = int(args[2]) if len(args) > 2 else 10
899921
cmd_similar(args[1], cfg, top_k)
900922
elif cmd == "tag":
901-
if len(args) < 3:
923+
if len(args) < 3 or sub_help:
902924
print("Usage: kb tag <file> tag1 [tag2...]")
903-
sys.exit(1)
925+
sys.exit(0 if sub_help else 1)
904926
cmd_tag(cfg, args[1], args[2:])
905927
elif cmd == "untag":
906-
if len(args) < 3:
928+
if len(args) < 3 or sub_help:
907929
print("Usage: kb untag <file> tag1 [tag2...]")
908-
sys.exit(1)
930+
sys.exit(0 if sub_help else 1)
909931
cmd_untag(cfg, args[1], args[2:])
910932
elif cmd == "tags":
933+
if sub_help:
934+
print("Usage: kb tags")
935+
sys.exit(0)
911936
cmd_tags(cfg)
912937
elif cmd == "list":
938+
if sub_help:
939+
print("Usage: kb list [--full]")
940+
sys.exit(0)
913941
cmd_list(cfg, full="--full" in args)
914942
elif cmd == "stats":
943+
if sub_help:
944+
print("Usage: kb stats")
945+
sys.exit(0)
915946
cmd_stats(cfg)
916947
elif cmd == "reset":
948+
if sub_help:
949+
print("Usage: kb reset")
950+
sys.exit(0)
917951
reset(cfg.db_path)
918952
else:
919953
print(f"Unknown command: {cmd}")

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)