fix(cli): constrain timeseries option values

This commit is contained in:
2026-06-05 13:43:32 +08:00
parent b7872f29a9
commit 9a7aad2d36
6 changed files with 280 additions and 64 deletions
+7 -6
View File
@@ -7,6 +7,7 @@ import typer
from .apps import component_option_app, network_app
from .common import emit_api, runtime_context
from .core import CLIError, require_network
from .option_types import ComponentOptionKind
@network_app.command("get-node-properties")
@@ -74,13 +75,13 @@ def network_get_all_pipe_properties(ctx: typer.Context) -> None:
@component_option_app.command("schema")
def component_option_schema(
ctx: typer.Context,
kind: Annotated[str, typer.Option("--kind", help="time|energy|pump-energy|network")],
kind: Annotated[ComponentOptionKind, typer.Option("--kind", help="选项类型,仅支持 time|energy|pump-energy|network")],
pump: Annotated[str | None, typer.Option("--pump", help="pump-energy 时需要的泵 ID")] = None,
) -> None:
runtime = runtime_context(ctx)
path = _component_option_path(kind, schema=True)
path = _component_option_path(kind.value, schema=True)
params = {"network": require_network(runtime)}
if kind == "pump-energy" and pump:
if kind == ComponentOptionKind.PUMP_ENERGY and pump:
params["pump"] = pump
emit_api(
ctx,
@@ -96,13 +97,13 @@ def component_option_schema(
@component_option_app.command("get")
def component_option_get(
ctx: typer.Context,
kind: Annotated[str, typer.Option("--kind", help="time|energy|pump-energy|network")],
kind: Annotated[ComponentOptionKind, typer.Option("--kind", help="选项类型,仅支持 time|energy|pump-energy|network")],
pump: Annotated[str | None, typer.Option("--pump", help="pump-energy 时需要的泵 ID")] = None,
) -> None:
runtime = runtime_context(ctx)
path = _component_option_path(kind, schema=False)
path = _component_option_path(kind.value, schema=False)
params = {"network": require_network(runtime)}
if kind == "pump-energy":
if kind == ComponentOptionKind.PUMP_ENERGY:
if not pump:
raise CLIError(
"CLI 参数错误",