~/bend-docscommunity

src/ez/app.bend source

src/ez/app.bend on the hub · documented module

# ez: the one binary. The line is a Shake.Cli (`L.spec`): `parse` binds the# command and its flags, and `get` / `on` read the bindings. How a line ends# is decided in ez/line.bend (`L.line`, `L.status`): a command runs, help is# shown and the line exits 0, or the line is misused and exits 1. This file# prints and exits as they say and runs the command, which is trusted# (below). `IO.args()` is copied so each word can be read more than once.# The repo's top-level main.bend calls this `main`, and is the file that gets# built. Build it native (`bend main.bend -o bin/ez.bin`); interpreted, bend's# own CLI would take the flags meant for ez.## Trusted, not proved: the interpreters (this file, ez/cmd.bend and each# command's run.bend) read the World and execute plans faithfully, and exit# with the status the planners' ends give. They make no decisions and are# kept small enough to review line by line; every decision is a planner's,# where the laws reach it. A failure an interpreter meets itself, a write# the system rejects, a build or link that fails, a fetch inside `ez tool`,# or a loop that runs out of fuel, exits 1. The words they are handed are# trusted in share/args.bend.import Baseimport shake@0.6.0.0/main.bend as Shakeimport ../share/args.bend as Argsimport ./cmd.bend as Cmdimport ./test.bend as Testimport ./prove.bend as Proveimport ../doctor/run.bend as DoctorRunimport ../tool/run.bend as ToolRunimport ../tool/world.bend as TWimport ../share/say.bend as Sayimport ../io/file.bend as Fimport ../ez/line.bend as Limport ../ws/run.bend as WsRun# `ez add`: the target, ref, entry and rename the line bound, in the memberdef dispatch.add(+matched: Shake.Matched) -> IO(Unit):  +target = L.get(matched, "target")  +ref = L.get(matched, "ref")  +entry = L.get(matched, "entry")  +rename = L.get(matched, "rename")  WsRun.in.member(_u => Cmd.add(target, ref, entry, rename))# `ez lock`: `--upgrade` and the package it is limited to, at the rootdef dispatch.lock(+matched: Shake.Matched) -> IO(Unit):  +up = Shake.on(matched, "upgrade")  +only = L.get(matched, "package")  WsRun.at.root(_u => Cmd.lock(up, only))# what a subcommand runs. `L.line` never runs `CHelp`, which names no# command; it is here so the match is whole, and it writes the help a bare# `ez` would. The directories `ez check` and `ez build` write into are made# by those commands once they know they will start bend (`Env.dirs`), so a# refused one leaves the directory as it found it.def dispatch(sub: L.Sub, +matched: Shake.Matched, +as: List<&2, String>) -> IO(Unit):  # noqa: L001 IO driver  match sub:    case L.CInit{}:      Cmd.init(L.get(matched, "name"), L.get(matched, "entry"),        L.get(matched, "description"))    case L.CAdd{}:      dispatch.add(matched)    case L.CRemove{}:      +name = L.get(matched, "name")      WsRun.in.member(_u => Cmd.remove(name))    case L.CLock{}:      dispatch.lock(matched)    case L.CFetch{}:      WsRun.at.root(_u => Cmd.fetch())    case L.CCheck{}:      WsRun.in.member(_u => Cmd.check())    case L.CBuild{}:      +out = L.get(matched, "out")      WsRun.in.member(_u => Cmd.build(out))    case L.CRun{}:      WsRun.in.member(_u => Cmd.run(as))    case L.CToolSync{}:      ToolRun.sync()    case L.CToolRun{}:      ToolRun.run(TW.Run{Args.tool.rest(as)}, L.get(matched, "target"),        L.get(matched, "entry"))    case L.CToolInstall{}:      ToolRun.run(TW.Install{}, L.get(matched, "target"), L.get(matched, "entry"))    case L.CToolUpgrade{}:      ToolRun.run(TW.Upgrade{}, L.get(matched, "target"), L.get(matched, "entry"))    case L.CPublish{}:      WsRun.in.member(_u => Cmd.publish())    case L.CTest{}:      Test.run()    case L.CProve{}:      Prove.run()    case L.CDoctor{}:      WsRun.at.root(_u => DoctorRun.run())    case L.CHelp{}:      IO.write(Shake.help(L.spec(), []))# `sync` with no tools is lock or install; a ledger that pins tools already# names the command that builds them. Anything else is the parser's own error.def hint.sync(is_sync: Bool) -> IO(Unit):  match is_sync:    case False{}:      IO.pure(Unit, Unit{})    case True{}:      do IO<Unit>:        m : Maybe<&2, String> <- F.read("ez.toml")        IO.print_err(Say.hint(Say.has.tools(F.text_of(m))))# what a line says: the command it names run, its help on stdout, or what# was wrong with it on stderr, with a hint for `ez sync`def go.say(how: L.Line, +as: List<&2, String>) -> IO(Unit):  match how:    case L.Runs{sub, +m}:      dispatch(sub, m, as)    case L.Shows{text}:      IO.write(text)    case L.Misuse{text}:      do IO<Unit>:        IO.print_err(text)        hint.sync(String.eq(Args.at(as, 0n), "sync"))# a status that is 0 ends nothing, and any other exits with itdef go.exit(zero: Bool, +code: U32) -> IO(Unit):  match zero:    case True{}:      IO.pure(Unit, Unit{})    case False{}:      IO.die(Unit, code, "")# a status decided before any command ran, exited with; a command's own end# is its owndef go.end(st: L.Status) -> IO(Unit):  match st:    case L.Exits{+code}:      go.exit(U32.is_eq(code, 0), code)    case L.Ends{}:      IO.pure(Unit, Unit{})# how the line ends, as `L.line` decided, and the status `L.status` gives itdef go.line(+how: L.Line, +as: List<&2, String>) -> IO(Unit):  do IO<Unit>:    go.say(how, as)    go.end(L.status(how))# the line taken apartdef go(+app: Shake.Cli, +as: List<&2, String>) -> IO(Unit):  # noqa: L001 IO driver  go.line(L.line(app, Shake.parse(app, Args.argv.of(as))), as)def main() -> IO(Unit):  # noqa: L001 IO entry point  do IO<Unit>:    as : List<&2, String> <- Args.all()    go(L.spec(), as)