Files
hose-use/src/ekb_cli/commands/agent/rule_create.py
T

39 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""ekb agent rule-create:新建审核规则"""
import typer
from rich import print as rprint
from ekb_cli.api import get_client
from ekb_cli.api.agent import save_rule
VALID_LEVELS = {"严重", "一般"}
def cmd_rule_create(
purpose: str = typer.Option(..., "--purpose", "-p", help="适用场景(规则名称)"),
description: str = typer.Option(..., "--desc", "-d", help="规则描述"),
level: str = typer.Option("严重", "--level", "-l", help="风险等级:严重 / 一般"),
):
"""新建审核规则"""
if level not in VALID_LEVELS:
rprint(f"[red]错误:--level 只接受 严重 / 一般,当前值:{level}[/red]")
raise typer.Exit(1)
payload = {"purpose": purpose, "description": description, "level": level}
with get_client() as client:
resp = save_rule(client, payload)
data = resp.get("data", {})
if not data:
rprint(f"[red]创建失败:{resp}[/red]")
raise typer.Exit(1)
rprint(f"[green]✓ 规则创建成功[/green]")
rprint(f" 编码:[bold]{data.get('code')}[/bold]")
rprint(f" ID:[dim]{data.get('id')}[/dim]")
rprint(f" 适用场景:{data.get('purpose')}")
rprint(f" 描述:{data.get('description')}")
rprint(f" 风险等级:{'[red]' if data.get('level') == '严重' else '[yellow]'}{data.get('level')}[/{'red' if data.get('level') == '严重' else 'yellow'}]")
rprint(f" 创建时间:[dim]{data.get('createTime')}[/dim]")