- ekb agent update: patch-style update, only overrides provided fields - ekb commands [group]: rich tree view of full command hierarchy - api/agent.py: add save_agent() - CLAUDE.md/README.md: simplify to layered structure
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
"""ekb commands [GROUP]:查看命令树"""
|
|
|
|
from typing import Optional
|
|
import typer
|
|
from rich.console import Console
|
|
from rich.tree import Tree
|
|
|
|
console = Console()
|
|
|
|
# 命令树定义:新增命令组/命令时在此同步维护
|
|
COMMAND_TREE = {
|
|
"auth": {
|
|
"_help": "管理企业认证",
|
|
"add": "添加企业认证",
|
|
"list": "列出所有企业",
|
|
"use": "切换当前企业",
|
|
"remove": "删除企业",
|
|
"whoami": "查看当前企业",
|
|
},
|
|
"agent": {
|
|
"_help": "智能审核 Agent 管理",
|
|
"list": "列出所有 Agent",
|
|
"get": "查看 Agent 详情 → ekb agent get <id> --help",
|
|
"update": "修改 Agent 配置 → ekb agent update <id> --help",
|
|
"logs": "查看审核日志",
|
|
},
|
|
}
|
|
|
|
|
|
def cmd_commands(group: Optional[str] = typer.Argument(None, help="命令组名称,如 auth / agent")):
|
|
"""查看命令树(不带参数显示全树,带组名只看该分支)"""
|
|
if group is not None:
|
|
if group not in COMMAND_TREE:
|
|
console.print(f"[red]未知命令组:{group}[/red]")
|
|
raise typer.Exit(1)
|
|
_print_group(group, COMMAND_TREE[group])
|
|
else:
|
|
root = Tree("[bold]ekb[/bold]")
|
|
for grp, cmds in COMMAND_TREE.items():
|
|
_build_branch(root, grp, cmds)
|
|
console.print(root)
|
|
console.print("\n[dim]查看某组详情:ekb commands <group>[/dim]")
|
|
console.print("[dim]查看命令参数:ekb <group> <command> --help[/dim]")
|
|
|
|
|
|
def _build_branch(parent, grp: str, cmds: dict):
|
|
branch = parent.add(f"[bold cyan]{grp}[/bold cyan] {cmds.get('_help', '')}")
|
|
for cmd, desc in cmds.items():
|
|
if cmd == "_help":
|
|
continue
|
|
branch.add(f"[green]{cmd}[/green] {desc}")
|
|
|
|
|
|
def _print_group(grp: str, cmds: dict):
|
|
tree = Tree(f"[bold]ekb[/bold] [bold cyan]{grp}[/bold cyan] {cmds.get('_help', '')}")
|
|
for cmd, desc in cmds.items():
|
|
if cmd == "_help":
|
|
continue
|
|
tree.add(f"[green]{cmd}[/green] {desc}")
|
|
console.print(tree)
|
|
console.print(f"\n[dim]查看命令参数:ekb {grp} <command> --help[/dim]")
|