整理 tjwater-cli 代码和文档
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import typer
|
||||
|
||||
from .core import DEFAULT_TIMEOUT, build_runtime_context, emit_success, request_json
|
||||
|
||||
|
||||
def runtime_context(ctx: typer.Context):
|
||||
obj = ctx.obj or {}
|
||||
return build_runtime_context(
|
||||
server=obj.get("server"),
|
||||
auth_context_path=obj.get("auth_context"),
|
||||
scheme=obj.get("scheme"),
|
||||
timeout=obj.get("timeout", DEFAULT_TIMEOUT),
|
||||
request_id=obj.get("request_id"),
|
||||
)
|
||||
|
||||
|
||||
def emit_api(
|
||||
ctx: typer.Context,
|
||||
*,
|
||||
summary: str,
|
||||
method: str,
|
||||
path: str,
|
||||
params: dict[str, Any] | None = None,
|
||||
json_body: Any = None,
|
||||
require_auth: bool = True,
|
||||
require_project: bool = False,
|
||||
require_network_ctx: bool = False,
|
||||
require_username_ctx: bool = False,
|
||||
next_commands: list[str] | None = None,
|
||||
) -> None:
|
||||
runtime = runtime_context(ctx)
|
||||
data, duration_ms = request_json(
|
||||
runtime,
|
||||
method=method,
|
||||
path=path,
|
||||
params=params,
|
||||
json_body=json_body,
|
||||
require_auth=require_auth,
|
||||
require_project=require_project,
|
||||
require_network_ctx=require_network_ctx,
|
||||
require_username_ctx=require_username_ctx,
|
||||
)
|
||||
emit_success(
|
||||
summary=summary,
|
||||
data=data,
|
||||
ctx=runtime,
|
||||
duration_ms=duration_ms,
|
||||
next_commands=next_commands,
|
||||
)
|
||||
Reference in New Issue
Block a user