拆分代码;约束cli命令
This commit is contained in:
+12
-12
@@ -39,15 +39,15 @@ COMMAND_DOCS: dict[tuple[str, ...], CommandDoc] = {
|
||||
path=("project", "list"),
|
||||
summary="列出当前用户可访问项目",
|
||||
description="调用 /meta/projects 返回项目列表。",
|
||||
examples=("tjwater --auth-context auth.json project list",),
|
||||
next_commands=("tjwater --auth-context auth.json project info",),
|
||||
examples=("tjwater-cli --auth-context auth.json project list",),
|
||||
next_commands=("tjwater-cli --auth-context auth.json project info",),
|
||||
output="项目摘要列表",
|
||||
),
|
||||
("project", "info"): CommandDoc(
|
||||
path=("project", "info"),
|
||||
summary="读取当前项目元数据",
|
||||
description="调用 /meta/project 返回当前 project 详情。",
|
||||
examples=("tjwater --auth-context auth.json project info",),
|
||||
examples=("tjwater-cli --auth-context auth.json project info",),
|
||||
output="项目元数据",
|
||||
),
|
||||
("project", "db-health"): CommandDoc(
|
||||
@@ -109,8 +109,8 @@ COMMAND_DOCS: dict[tuple[str, ...], CommandDoc] = {
|
||||
CommandOptionDoc("duration", "持续分钟数", required=True),
|
||||
),
|
||||
next_commands=(
|
||||
"tjwater --auth-context auth.json data timeseries realtime links --start-time 2025-01-02T03:04:05+08:00 --end-time 2025-01-02T03:34:05+08:00",
|
||||
"tjwater --auth-context auth.json data timeseries realtime nodes --start-time 2025-01-02T03:04:05+08:00 --end-time 2025-01-02T03:34:05+08:00",
|
||||
"tjwater-cli --auth-context auth.json data timeseries realtime links --start-time 2025-01-02T03:04:05+08:00 --end-time 2025-01-02T03:34:05+08:00",
|
||||
"tjwater-cli --auth-context auth.json data timeseries realtime nodes --start-time 2025-01-02T03:04:05+08:00 --end-time 2025-01-02T03:34:05+08:00",
|
||||
),
|
||||
output="模拟触发结果;实时数据需通过 data timeseries 命令按时间段查询",
|
||||
),
|
||||
@@ -125,11 +125,11 @@ COMMAND_DOCS: dict[tuple[str, ...], CommandDoc] = {
|
||||
CommandOptionDoc("scheme", "方案名称"),
|
||||
),
|
||||
examples=(
|
||||
"tjwater --auth-context auth.json analysis burst --start-time 2025-01-02T03:04:05+08:00 --duration 30 --burst-file ./burst.json --scheme burst_case_01",
|
||||
"tjwater-cli --auth-context auth.json analysis burst --start-time 2025-01-02T03:04:05+08:00 --duration 30 --burst-file ./burst.json --scheme burst_case_01",
|
||||
),
|
||||
next_commands=(
|
||||
"tjwater --auth-context auth.json data scheme get --name burst_case_01",
|
||||
"tjwater --auth-context auth.json data scheme list",
|
||||
"tjwater-cli --auth-context auth.json data scheme get --name burst_case_01",
|
||||
"tjwater-cli --auth-context auth.json data scheme list",
|
||||
),
|
||||
output="分析执行结果;方案详情需通过 data scheme 命令单独查询",
|
||||
),
|
||||
@@ -138,7 +138,7 @@ COMMAND_DOCS: dict[tuple[str, ...], CommandDoc] = {
|
||||
summary="执行阀门关闭或隔离分析",
|
||||
description="mode=close 使用 valve 列表;mode=isolation 需要 accident element,可选 disabled-valve。",
|
||||
examples=(
|
||||
"tjwater --auth-context auth.json analysis valve --mode close --start-time 2025-01-02T03:04:05+08:00 --valve V1 --duration 900",
|
||||
"tjwater-cli --auth-context auth.json analysis valve --mode close --start-time 2025-01-02T03:04:05+08:00 --valve V1 --duration 900",
|
||||
),
|
||||
),
|
||||
("analysis", "flushing"): CommandDoc(
|
||||
@@ -422,13 +422,13 @@ def list_subcommands(path_prefix: tuple[str, ...], summary: str | None = None) -
|
||||
seen.add(subcommand)
|
||||
current_path = (*path_prefix, subcommand)
|
||||
is_group = has_subcommands(current_path)
|
||||
usage = f"tjwater {' '.join(current_path)} help" if is_group else (doc.examples[0] if doc.examples else _build_usage(doc))
|
||||
usage = f"tjwater-cli {' '.join(current_path)} help" if is_group else (doc.examples[0] if doc.examples else _build_usage(doc))
|
||||
commands.append(
|
||||
{
|
||||
"command": " ".join(current_path),
|
||||
"summary": get_group_summary(current_path) if is_group else doc.summary,
|
||||
"usage": usage,
|
||||
"example": f"tjwater {' '.join(current_path)} help" if is_group else _build_examples(doc)[0],
|
||||
"example": f"tjwater-cli {' '.join(current_path)} help" if is_group else _build_examples(doc)[0],
|
||||
}
|
||||
)
|
||||
return {
|
||||
@@ -440,7 +440,7 @@ def list_subcommands(path_prefix: tuple[str, ...], summary: str | None = None) -
|
||||
|
||||
|
||||
def _build_usage(doc: CommandDoc) -> str:
|
||||
parts = ["tjwater", *doc.path]
|
||||
parts = ["tjwater-cli", *doc.path]
|
||||
for option in doc.options:
|
||||
placeholder = option.name.upper().replace("-", "_")
|
||||
if option.required:
|
||||
|
||||
Reference in New Issue
Block a user