src/args.bend
shake@0.7.0.0 · 54 lines · 6 definitions
1
2
3
4
5
6import Base
7import shake@0.7.0.0/src/cli.bend as C
8
9
10def copy(xs: List<&1, String>) -> List<&2, String>:
11 match xs:
12 case Nil{}:
13 Nil{}
14 case Con{+h, t}:
15 h <> copy(t)
16
17
18def words(xs: List<&1, String>) -> List<&2, String>:
19 match xs:
20 case Nil{}:
21 Nil{}
22 case Con{_h, t}:
23 copy(t)
24
25
26def argv() -> IO(List<&2, String>):
27 IO.bind(List<&1, String>, List<&2, String>, IO.args(),
28 xs => IO.pure(List<&2, String>, words(xs)))
29
30
31def kept(
32 +name: String,
33 got: Result<&1, &1, U32 & String, String>,
34 rest: List<&2, C.Var>
35) -> List<&2, C.Var>:
36 match got:
37 case Done{vv}:
38 (name, vv) <> rest
39 case Fail{_e}:
40 rest
41
42
43def vars(names: List<&2, String>) -> IO(List<&2, C.Var>):
44 match names:
45 case Nil{}:
46 IO.pure(List<&2, C.Var>, [])
47 case Con{+hh, tt}:
48 IO.bind(Result<&1, &1, U32 & String, String>, List<&2, C.Var>, IO.get_env(hh),
49 got => IO.bind(List<&2, C.Var>, List<&2, C.Var>, vars(tt),
50 rest => IO.pure(List<&2, C.Var>, kept(hh, got, rest))))
51
52
53def env_vars(spec: C.Cli) -> IO(List<&2, C.Var>):
54 vars(C.env.names(spec))