main.bend
bolt@1.11.0.0 · 45 lines · 0 definitions
1# bolt: a linter, checker and language server for Bend 2.
2#
3# The one binary. Shake parses the line: `lint`, or a word that is no
4# subcommand, or nothing, lints the files named after it (every `.bend` file
5# under the current directory when none are); `check` runs the checker on
6# them; `lsp` serves an editor over stdio; `help` (or `--help`) prints usage; `--version`
7# prints the release and the short commit when the build has one. Build it
8# native (`bend main.bend -o bin/bolt.bin`). `bolt lsp` runs on the cores:
9# with no `--gpu` it is `--gpu off`, and `--gpu on` or `--gpu 4GB` asks for
10# the device. The runtime takes `--gpu` out of the line itself. What the line
11# does is Args.out's decision (src/LAWS.bend proves it); this file only does
12# it, and LAWS.bend states what src/stop.bend's say and leave do.
13# Everything under src/ is internal.
14import Base
15import bolt@1.11.0.0/src/args.bend as Args
16import bolt@1.11.0.0/src/lint.bend as Lint
17import bolt@1.11.0.0/src/check.bend as Check
18import bolt@1.11.0.0/src/lsp/run.bend as Lsp
19import bolt@1.11.0.0/src/lsp/checker/bend.bend as BendChecker
20import bolt@1.11.0.0/src/stop.bend as Stop
21
22# what a subcommand runs, over the files after it
23def dispatch(cmd: Args.Cmd, paths: List<&2, String>) -> IO(Unit): # noqa: L001 IO driver
24 match cmd:
25 case Args.CLint{}:
26 Lint.run(paths)
27 case Args.CCheck{}:
28 Check.run(~BendChecker.service(), paths)
29 case Args.CLsp{}:
30 Lsp.run()
31
32# what a parsed line does, done
33def perform(oo: Args.Out) -> IO(Unit): # noqa: L001 IO driver
34 match oo:
35 case Args.Stop{to, text, code}:
36 do IO<Unit>:
37 Stop.say(to, text)
38 Stop.leave(code)
39 case Args.Go{cmd, paths}:
40 dispatch(cmd, paths)
41
42def main() -> IO(Unit): # noqa: L001 IO entry point
43 do IO<Unit>:
44 +av : List<&2, String> <- Args.argv()
45 perform(Args.out(Args.parse(Args.line(av))))