src/stop.bend
bolt@1.12.0.0 · 26 lines · 0 definitions
1# src/stop: a Stop done (Args.out's decision to print and exit): a text on
2# its stream, then the exit code. Pure but for the IO it returns, and apart
3# from main.bend, so its laws (the root LAWS.bend) reach no foreign code.
4import Base
5import bolt@1.12.0.0/src/args.bend as Args
6
7# a text on its stream
8def say(to: Args.Stream, text: String) -> IO(Unit):
9 match to:
10 case Args.Line{}:
11 IO.print(text)
12 case Args.Page{}:
13 IO.write(text)
14 case Args.Err{}:
15 IO.print_err(text)
16
17def leave.at(zero: Bool, code: U32) -> IO(Unit):
18 match zero:
19 case True{}:
20 IO.pure(Unit, Unit{})
21 case False{}:
22 IO.die(Unit, code, "")
23
24# exit with a code: 0 falls through, any other ends the run with it
25def leave(+code: U32) -> IO(Unit):
26 leave.at(U32.is_eq(code, 0), code)