优化:截断提示改为显示完整文本总字符数,--full 仍用表格输出
This commit is contained in:
1 parent
f72b05f2d2
commit
468b13437a
1 file changed
+38
-15
@@ -13,8 +13,18 @@ console = Console()
|
||||
STATE_MAP = {0: "[green]启用[/green]", 1: "[dim]未启用(未关联审批流)[/dim]"}
|
||||
MODE_MAP = {0: "全自动", 1: "半自动", 2: "辅助"}
|
||||
|
||||
DESC_MAX = 24
|
||||
PURPOSE_MAX = 16
|
||||
|
||||
def cmd_detail(agent_id: str = typer.Argument(..., help="Agent ID")):
|
||||
|
||||
def _truncated(text: str, max_width: int) -> bool:
|
||||
return len(text) > max_width
|
||||
|
||||
|
||||
def cmd_detail(
|
||||
agent_id: str = typer.Argument(..., help="Agent ID"),
|
||||
full: bool = typer.Option(False, "--full", "-f", help="显示完整内容,不截断规则字段"),
|
||||
):
|
||||
"""查看 Agent 详情"""
|
||||
with get_client() as client:
|
||||
resp = get_agent(client, agent_id)
|
||||
@@ -53,26 +63,39 @@ def cmd_detail(agent_id: str = typer.Argument(..., help="Agent ID")):
|
||||
rules = d.get("agentRule", [])
|
||||
if rules:
|
||||
table = Table(title="关联规则", show_lines=True)
|
||||
table.add_column("规则描述", max_width=24, no_wrap=True)
|
||||
table.add_column("规则编码", style="dim", no_wrap=True)
|
||||
table.add_column("适用场景", max_width=16, no_wrap=True)
|
||||
table.add_column("风险等级", no_wrap=True)
|
||||
table.add_column("更新日期", style="dim", no_wrap=True)
|
||||
table.add_column("ID", style="dim", no_wrap=True)
|
||||
if full:
|
||||
table.add_column("规则描述")
|
||||
table.add_column("规则编码", style="dim", no_wrap=True)
|
||||
table.add_column("适用场景")
|
||||
table.add_column("风险等级", no_wrap=True)
|
||||
table.add_column("更新日期", style="dim", no_wrap=True)
|
||||
table.add_column("ID", style="dim", no_wrap=True)
|
||||
else:
|
||||
table.add_column("规则描述", max_width=DESC_MAX, no_wrap=True)
|
||||
table.add_column("规则编码", style="dim", no_wrap=True)
|
||||
table.add_column("适用场景", max_width=PURPOSE_MAX, no_wrap=True)
|
||||
table.add_column("风险等级", no_wrap=True)
|
||||
table.add_column("更新日期", style="dim", no_wrap=True)
|
||||
table.add_column("ID", style="dim", no_wrap=True)
|
||||
|
||||
any_truncated = False
|
||||
total_chars = 0
|
||||
for r in rules:
|
||||
level = r.get("level", "")
|
||||
level_str = f"[red]{level}[/red]" if level == "严重" else f"[yellow]{level}[/yellow]"
|
||||
update_date = (r.get("updateTime", "") or "")[:10]
|
||||
desc = r.get("description", "")
|
||||
purpose = r.get("purpose", "")
|
||||
table.add_row(
|
||||
desc,
|
||||
r.get("code", ""),
|
||||
purpose,
|
||||
level_str,
|
||||
update_date,
|
||||
r.get("id", ""),
|
||||
)
|
||||
total_chars += len(desc) + len(purpose)
|
||||
if not full and (_truncated(desc, DESC_MAX) or _truncated(purpose, PURPOSE_MAX)):
|
||||
any_truncated = True
|
||||
table.add_row(desc, r.get("code", ""), purpose, level_str, update_date, r.get("id", ""))
|
||||
|
||||
console.print(table)
|
||||
|
||||
if any_truncated:
|
||||
rprint(f"[yellow]⚠ 部分规则字段已截断,完整规则文本共 {total_chars} 字符[/yellow]")
|
||||
rprint("[dim]使用 --full 参数获取完整内容:ekb agent get <id> --full[/dim]")
|
||||
else:
|
||||
rprint("[dim](未关联任何规则)[/dim]")
|
||||
|
||||
Reference in new issue
Block a user