-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeow.py
More file actions
63 lines (50 loc) · 1.83 KB
/
Copy pathmeow.py
File metadata and controls
63 lines (50 loc) · 1.83 KB
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
# meow.py
"""The world's most unnecessarily engineered cat."""
from __future__ import annotations
import argparse
import json
import sys
from harness.caesar import laugh, run_caesar
from harness.judge import mutations
from harness.provenance import Provenance
from harness.roster import discover
from harness.tournament import run_arena, run_tournament
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(prog="meow", description="hace un gato")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--list-gladiators", action="store_true")
group.add_argument("--arena", metavar="NAME")
group.add_argument("--tournament", action="store_true")
group.add_argument("--judge", action="store_true")
group.add_argument("--caesar", action="store_true")
try:
args = parser.parse_args(argv)
except SystemExit as exc:
# argparse uses exit 0 for --help and 2 for invalid arguments.
return exc.code if isinstance(exc.code, int) else 1
if args.list_gladiators:
for g in discover():
print("%-12s %-24s %s" % (
g.language, ",".join(g.disciplines) or "-", ",".join(g.arenas) or "-"))
return 0
if args.arena:
result = run_arena(args.arena, discover(), Provenance())
print(json.dumps(result, indent=2, sort_keys=True))
return 0
if args.tournament:
result = run_tournament()
print(result["cat"])
print(laugh().strip())
return 0
if args.judge:
result = run_tournament()
for name, maimed in mutations(result["cat"]):
print("=== %s ===" % name)
print(maimed)
return 0
if args.caesar:
print(run_caesar()["cat"])
return 0
return 1
if __name__ == "__main__":
sys.exit(main())