cli/main.bend
near-v-framework@0.2.0.0 · 56 lines · 0 definitions
1import Base
2import near-v-framework@0.2.0.0/cli/v.bend as M
3import near-v-framework@0.2.0.0/cli/project.bend as P
4import near-v-framework@0.2.0.0/cli/vimport.bend as I
5import near-v-framework@0.2.0.0/cli/vdry.bend as D
6
7# The `v` command. Its commands are namespaced by what they act on: `v system ...` for a system.
8def usage() -> IO(Unit):
9 IO.print("usage: v system check | plan | snapshot | import | dryrun | deploy | diagram [out.png]")
10
11def plan() -> IO(Unit):
12 do IO<Unit>:
13 p : String <- P.run_bend("plan.bend")
14 IO.print(p)
15
16def pick_io(c: Bool, a: IO(Unit), b: IO(Unit)) -> IO(Unit):
17 match c:
18 case True{}:
19 a
20 case False{}:
21 b
22
23def first_or(xs: List<String>, d: String) -> String:
24 match xs:
25 case []:
26 d
27 case x <> _:
28 x
29
30def run(+cmd: String, rest: List<String>) -> IO(Unit):
31 pick_io(String.eq(cmd, "check"), M.check(),
32 pick_io(String.eq(cmd, "plan"), plan(),
33 pick_io(String.eq(cmd, "snapshot"), M.snapshot_only(),
34 pick_io(String.eq(cmd, "import"), I.import_mac(),
35 pick_io(String.eq(cmd, "dryrun"), D.dryrun(),
36 pick_io(String.eq(cmd, "deploy"), M.deploy(),
37 pick_io(String.eq(cmd, "diagram"), M.diagram(first_or(rest, "diagram.png")), usage())))))))
38
39def system(args: List<String>) -> IO(Unit):
40 match args:
41 case []:
42 usage()
43 case cmd <> rest:
44 run(cmd, rest)
45
46def dispatch(args: List<String>) -> IO(Unit):
47 match args:
48 case []:
49 usage()
50 case +ns <> rest:
51 pick_io(String.eq(ns, "system"), system(rest), usage())
52
53def main() -> IO(Unit):
54 do IO<Unit>:
55 args : List<String> <- IO.args()
56 dispatch(args)