src/pub/run.bend
ezx@1.11.0.0 · 114 lines · 8 definitions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21import Base
22import snap@1.4.0.0/main.bend as R
23import ezx@1.11.0.0/src/io/file.bend as F
24import ezx@1.11.0.0/src/lock/run.bend as Run
25import ezx@1.11.0.0/src/tool/run.bend as ToolRun
26import ezx@1.11.0.0/src/tool/world.bend as TW
27import ezx@1.11.0.0/src/hub/hub.bend as Web
28import ezx@1.11.0.0/src/hub/get.bend as Net
29import ezx@1.11.0.0/src/share/env.bend as Env
30import ezx@1.11.0.0/src/pub/world.bend as PW
31import ezx@1.11.0.0/src/pub/plan.bend as PP
32import ezx@1.11.0.0/src/ws/run.bend as WsRun
33
34
35def ran(+out: String) -> PW.Answer:
36 PW.Ran{R.ok(out), R.text(out)}
37
38
39def answer(+lib: String, ask: PW.Ask) -> IO(PW.Answer):
40 match ask:
41 case PW.Tool{q}:
42 do IO<PW.Answer>:
43 a : TW.Answer <- ToolRun.answer(q)
44 return PW.Told{a}
45 case PW.Tracked{}:
46 do IO<PW.Answer>:
47 +out : String <- R.exec(["git", "-c", "core.quotePath=false", "ls-files", "-v"])
48 return ran(out)
49 case PW.Upload{+entry, +named, says}:
50 do IO<PW.Answer>:
51 IO.print_err(says)
52 +out : String <- R.exec(Env.line(lib, PP.upload.line(entry, named)))
53 return ran(out)
54 case PW.Lock{}:
55 do IO<PW.Answer>:
56 at : String <- WsRun.lock.path()
57 m : Maybe<&2, String> <- F.read(at)
58 return PW.Told{TW.Plain{m}}
59 case PW.Hub{+url}:
60 do IO<PW.Answer>:
61 +out : String <- Net.get(url)
62 return ran(out)
63
64
65def answer.all(+lib: String, asks: List<&2, PW.Ask>) -> IO(List<&2, PW.Reply>):
66 match asks:
67 case []:
68 IO.pure(List<&2, PW.Reply>, [])
69 case +h <> t:
70 do IO<List<&2, PW.Reply>>:
71 a : PW.Answer <- answer(lib, h)
72 rest : List<&2, PW.Reply> <- answer.all(lib, t)
73 return PW.Reply{h, a} <> rest
74
75
76def more(world: PW.World, rs: List<&2, PW.Reply>) -> PW.World:
77 PW.World{here, ledger, replies} = world
78 PW.World{here, ledger, List.append(&2, PW.Reply, replies, rs)}
79
80
81
82def loop.step(st: PP.Step, +lib: String, world: PW.World, go: PW.World -> IO(Unit)) -> IO(Unit):
83 match st:
84 case PP.Asking{asks}:
85 do IO<Unit>:
86 rs : List<&2, PW.Reply> <- answer.all(lib, asks)
87 go(more(world, rs))
88 case PP.Run{pl}:
89 Run.exec.plan(lib, pl)
90
91
92
93
94
95def rounds() -> Nat:
96 U32.to_nat(100000)
97
98
99
100def loop(fuel: Nat, +lib: String, +world: PW.World) -> IO(Unit):
101 match fuel:
102 case 0n:
103 IO.die(Unit, 1, "ez: ez publish kept asking questions")
104 case 1n+f:
105 loop.step(PP.step(world), lib, world, w => loop(f, lib, w))
106
107
108
109def run() -> IO(Unit):
110 do IO<Unit>:
111 lib : String <- Env.lib()
112 +pwd : String <- R.exec(["pwd"])
113 led : Maybe<&2, String> <- F.read(PW.toml())
114 loop(rounds(), lib, PW.World{String.trim(R.text(pwd)), led, []})