Skip to content

Commit 917dbcd

Browse files
committed
fix(cli): --no-exit-by-risk flag and risk|risk_level compatibility
1 parent 7719aaf commit 917dbcd

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/diff_risk_dashboard/cli.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@
44
import json
55
import sys
66
from pathlib import Path
7-
from typing import Literal, TypedDict
87

8+
from .core import Summary as CoreSummary
99
from .core import summarize_apv_json
1010
from .report import to_markdown
1111

12-
13-
class Summary(TypedDict):
14-
total: int
15-
worst: str
16-
risk: Literal["red", "yellow", "green"]
17-
by_severity: dict
12+
Summary = CoreSummary
1813

1914

2015
def _print_table(summary: Summary) -> None:
@@ -26,7 +21,6 @@ def _print_table(summary: Summary) -> None:
2621

2722

2823
def _exit_code(risk: str) -> int:
29-
# 0=green, 1=yellow, 2=red
3024
return {"green": 0, "yellow": 1, "red": 2}.get(risk, 0)
3125

3226

@@ -44,18 +38,27 @@ def main() -> int:
4438
"-o", "--output", default="-", help="Archivo de salida; '-' = stdout (por defecto)"
4539
)
4640
p.add_argument(
47-
"--no-exit-by-risk", action="store_true", help="No ajustar el exit code por nivel de riesgo"
41+
"--no-exit-by-risk",
42+
dest="no_exit_by_risk",
43+
action="store_true",
44+
help="No ajustar el exit code por nivel de riesgo",
4845
)
4946
args = p.parse_args()
5047

5148
summary: Summary = summarize_apv_json(args.input) # path o texto
52-
out = ""
49+
50+
# compat: aceptar 'risk' o 'risk_level'
51+
risk = summary.get("risk", summary.get("risk_level", "green")) # type: ignore[assignment]
52+
if "risk" not in summary:
53+
summary["risk"] = risk # type: ignore[index]
54+
5355
if args.format == "json":
5456
out = json.dumps(summary, indent=2)
5557
elif args.format == "md":
5658
out = to_markdown(summary)
5759
else:
5860
_print_table(summary)
61+
out = ""
5962

6063
if args.format in {"json", "md"}:
6164
if args.output == "-":
@@ -64,8 +67,8 @@ def main() -> int:
6467
Path(args.output).write_text(out, encoding="utf-8")
6568
print(f"Wrote {args.output}", file=sys.stderr)
6669

67-
if not args.no - exit - by - risk:
68-
return _exit_code(summary["risk"])
70+
if not args.no_exit_by_risk:
71+
return _exit_code(risk)
6972
return 0
7073

7174

0 commit comments

Comments
 (0)