File size: 2,350 Bytes
200cb0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Command-line validation harness for Iris."""

from __future__ import annotations

import argparse
import sys

from iris.engine import IrisEngine
from iris.errors import IrisError
from iris.seeds import DEFAULT_IDEAS
from iris.spiral import SpiralRun, run_spiral as collect_spiral


def main(argv: list[str] | None = None) -> int:
    parser = argparse.ArgumentParser(
        description="Run the Iris constraint spiral on one or more ideas."
    )
    parser.add_argument(
        "ideas",
        nargs="*",
        help="Idea(s) to validate. If omitted, use the seeded Day 1 ideas.",
    )
    parser.add_argument(
        "--all",
        action="store_true",
        help="Run the seeded Day 1 validation ideas.",
    )
    parser.add_argument(
        "--rings",
        type=int,
        default=4,
        help="Number of pressure rings before the center distillation.",
    )
    args = parser.parse_args(argv)

    if args.rings < 1:
        parser.error("--rings must be at least 1")

    ideas = DEFAULT_IDEAS if args.all or not args.ideas else args.ideas
    engine = IrisEngine()

    for index, idea in enumerate(ideas, start=1):
        print_spiral_header(index, len(ideas), idea)
        try:
            run_spiral(engine, idea, args.rings)
        except IrisError as exc:
            print(f"ERROR: {exc}", file=sys.stderr)
            return 1

    return 0


def run_spiral(engine: IrisEngine, idea: str, rings: int) -> None:
    print_spiral(collect_spiral(engine, idea, rings))


def print_spiral(run: SpiralRun) -> None:
    total = len(run.pressures)
    for depth, result in enumerate(run.pressures, start=1):
        print(f"Ring {depth}/{total}")
        print(f"Pressure: {result.pressure}")
        if result.alternative:
            print(f"Alternative: {result.alternative}")
        print(f"Why it bites: {result.why_it_bites}")
        print()

    print("Center")
    print(f"Actor: {run.center.actor}")
    print(f"Situation: {run.center.situation}")
    print(f"Assumption to test: {run.center.assumption_to_test}")
    print(f"Next step: {run.center.next_step}")
    print()


def print_spiral_header(index: int, total: int, idea: str) -> None:
    print("=" * 72)
    print(f"Spiral {index}/{total}")
    print(f"Idea: {idea}")
    print("=" * 72)


if __name__ == "__main__":
    raise SystemExit(main())