fix(cli): constrain timeseries option values
This commit is contained in:
@@ -31,6 +31,7 @@ from .core import (
|
||||
require_username,
|
||||
resolve_scheme,
|
||||
)
|
||||
from .option_types import DataSource, ValveMode
|
||||
|
||||
|
||||
@simulation_app.command("run")
|
||||
@@ -100,7 +101,7 @@ def analysis_burst(
|
||||
@analysis_app.command("valve")
|
||||
def analysis_valve(
|
||||
ctx: typer.Context,
|
||||
mode: Annotated[str, typer.Option("--mode", help="close|isolation")],
|
||||
mode: Annotated[ValveMode, typer.Option("--mode", help="分析模式,仅支持 close|isolation")],
|
||||
start_time: Annotated[str | None, typer.Option("--start-time", help="close 模式需要")] = None,
|
||||
valve: Annotated[list[str] | None, typer.Option("--valve", help="阀门 ID,可重复")] = None,
|
||||
element: Annotated[list[str] | None, typer.Option("--element", help="isolation 模式的事故元素,可重复")] = None,
|
||||
@@ -110,7 +111,7 @@ def analysis_valve(
|
||||
) -> None:
|
||||
runtime = runtime_context(ctx)
|
||||
network = require_network(runtime)
|
||||
if mode == "close":
|
||||
if mode == ValveMode.CLOSE:
|
||||
if not start_time or not valve:
|
||||
raise CLIError(
|
||||
"CLI 参数错误",
|
||||
@@ -135,7 +136,7 @@ def analysis_valve(
|
||||
require_network_ctx=True,
|
||||
)
|
||||
return
|
||||
if mode == "isolation":
|
||||
if mode == ValveMode.ISOLATION:
|
||||
if not element:
|
||||
raise CLIError(
|
||||
"CLI 参数错误",
|
||||
@@ -156,12 +157,7 @@ def analysis_valve(
|
||||
require_network_ctx=True,
|
||||
)
|
||||
return
|
||||
raise CLIError(
|
||||
"CLI 参数错误",
|
||||
code="INVALID_MODE",
|
||||
message="--mode must be close or isolation",
|
||||
exit_code=2,
|
||||
)
|
||||
raise AssertionError(f"unreachable valve mode: {mode}")
|
||||
|
||||
|
||||
@analysis_app.command("flushing")
|
||||
@@ -397,7 +393,7 @@ def analysis_burst_location_locate(
|
||||
end_time: Annotated[str, typer.Option("--end-time", help="RFC3339 结束时间")],
|
||||
burst_leakage: Annotated[float, typer.Option("--burst-leakage", help="爆管漏水量")],
|
||||
scheme: Annotated[str | None, typer.Option("--scheme", help="方案名称")] = None,
|
||||
data_source: Annotated[str, typer.Option("--data-source", help="monitoring|simulation")] = "monitoring",
|
||||
data_source: Annotated[DataSource, typer.Option("--data-source", help="数据来源,仅支持 monitoring|simulation")] = DataSource.MONITORING,
|
||||
pressure_scada_id: Annotated[list[str] | None, typer.Option("--pressure-scada-id", help="压力 SCADA ID,可重复")] = None,
|
||||
flow_scada_id: Annotated[list[str] | None, typer.Option("--flow-scada-id", help="流量 SCADA ID,可重复")] = None,
|
||||
pressure_file: Annotated[Path | None, typer.Option("--pressure-file", help="包含 burst_pressure/normal_pressure 的 JSON 文件")] = None,
|
||||
@@ -410,7 +406,7 @@ def analysis_burst_location_locate(
|
||||
body = {
|
||||
"network": require_network(runtime),
|
||||
"scheme_name": resolve_scheme(runtime, scheme, required=True),
|
||||
"data_source": data_source,
|
||||
"data_source": data_source.value,
|
||||
"scada_burst_start": parse_time_with_timezone(start_time, option_name="--start-time").isoformat(),
|
||||
"scada_burst_end": parse_time_with_timezone(end_time, option_name="--end-time").isoformat(),
|
||||
"burst_leakage": burst_leakage,
|
||||
|
||||
Reference in New Issue
Block a user