拆分代码;约束cli命令

This commit is contained in:
2026-06-02 14:54:08 +08:00
parent 9b8a517092
commit 40e699e173
17 changed files with 395 additions and 267 deletions
+7 -10
View File
@@ -44,11 +44,8 @@ def root_callback(
register_group_help_commands()
@app.command("help", context_settings={"allow_extra_args": True, "ignore_unknown_options": True})
def help_command(
ctx: typer.Context,
json_output: Annotated[bool, typer.Option("--json", help="输出 JSON")] = False,
) -> None:
@app.command("help", context_settings={"allow_extra_args": True})
def help_command(ctx: typer.Context) -> None:
command_path = list(ctx.args)
payload, is_index = resolve_help_payload(tuple(command_path))
if payload is None:
@@ -61,13 +58,13 @@ def help_command(
server=None,
request_id=None,
data={
"usage": "tjwater help <command-path>",
"examples": ["tjwater help simulation run", "tjwater simulation help"],
"usage": "tjwater-cli help <command-path>",
"examples": ["tjwater-cli help simulation run", "tjwater-cli simulation help"],
},
next_commands=["tjwater help", "tjwater help simulation"],
next_commands=["tjwater-cli help", "tjwater-cli help simulation"],
)
raise typer.Exit(code=2)
emit_help_payload(payload, json_output=json_output, is_index=is_index)
emit_help_payload(payload)
# Must run at import time because tests call runner.invoke(app, ...) directly.
@@ -76,7 +73,7 @@ apply_typer_help_metadata()
def main(argv: list[str] | None = None) -> int:
try:
app(args=argv if argv is not None else sys.argv[1:], prog_name="tjwater", standalone_mode=False)
app(args=argv if argv is not None else sys.argv[1:], prog_name="tjwater-cli", standalone_mode=False)
return 0
except CLIError as exc:
click_ctx = click.get_current_context(silent=True)