-
Notifications
You must be signed in to change notification settings - Fork 18
/
__main__.py
36 lines (32 loc) · 1.13 KB
/
__main__.py
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
import itertools
import json
import operator
from .main import run, RuleType
def wrap(n):
def inner(it):
while it:
lens = list(map(len, it))
csum = [sum(lens[:i+1]) for i in range(len(lens))]
amnt = sum(a+b<n for a, b in zip(csum, itertools.count()))
yield " ".join(it[0:amnt])
it = it[amnt:]
return inner
if __name__ == "__main__":
import sys
results = sorted(run(*(v for v in sys.argv[1:] if not v.startswith("--")), rule_type=RuleType.from_argv(sys.argv)))
if "--json" in sys.argv:
json.dump(results, sys.stdout)
else:
for k, rs in itertools.groupby(results, operator.itemgetter(0)):
rs = list(rs)
print("Feature:", k)
print(" URL:", rs[0][1])
print()
for k, rs in itertools.groupby(rs, operator.itemgetter(2)):
print(" Step:", k)
print()
for r in rs:
print(" *", r[3])
for ln in wrap(80)(r[4].split(' ')):
print(" ", ln)
print()