src/args.bend checks
raw source on the hub · import bolt@1.57.0.0/src/args.bend as Args
src/args: bolt's command line, parsed by shake. bolt [lint] [file..],
bolt check file.., bolt fmt [--check] [file..], bolt lsp,
bolt --version. A rest positional at the root (and on
lint / check) takes every leftover word, so bolt a.bend b.bend lints
those files. help is shake's usage page, and --help asks for the same
page (line). IO.args gives the program as invoked first, then its
arguments (bend 2.0.32); argv drops the program. A compiled binary passes
its whole line through except its runtime options, which stand between
+RTS and -RTS (bend 2.0.38): --threads and --gpu outside that
bracket reach the program, and --RTS hands everything after it to the
program. --help reaches the program (bend 2.0.29).
out is every decision the line makes, as data: what to print, where, and
the exit code, or the subcommand to run and its files. main only does it.
Only shake's interface (main.bend) is read here; what parse answers for a
given argv is shake's guarantee, not bolt's: shake v0.6.0, pinned by hash,
proves it in its own gate, and the laws naming an argv take shake's answer as
a premise and prove what bolt does with it. Of shake's assumptions bolt
trusts one: the words a compiled bolt's argv holds are the runtime's (its
options, between +RTS and -RTS, never reach it), which no law reaches.
5 imports
import Base import shake@0.6.0.0/main.bend as Shake import ./version.bend as Ver import ./build_rev.bend as Rev import ./lazy/lazy.bend as Lazy
Types
type Cmd source · line 124 · raw
Data
a subcommand; fmt carries whether it only checks
CLintCmd
CCheckCmd
CLspCmd
CFmt@check:Bool -> Cmd
type Stream source · line 141 · raw
Data
where a line that stops puts its text
LineStream
PageStream
ErrStream
type Out source · line 148 · raw
Data
what a parsed line does: print a text and exit with a code, or run a subcommand over files (which then exits as that command decides)
Stop@to:Stream -> @text:String -> @code:U32 -> Out
Go@cmd:Cmd -> @paths:List<&2, String> -> Out
Definitions
def widen source · line 28 · raw
@ss:List<&1, String> -> List<&2, String>
the line at the quantity the rest of bolt reads it at (IO.args gives each argument once)
def args_of source · line 37 · raw
@s:List<&1, String> -> List<&2, String>
the arguments of IO.args's line: the program as invoked comes first, and is dropped
def argv source · line 45 · raw
IO(List<&2, String>)
bolt's command line: its arguments, without the program
def is_cmd source · line 51 · raw
@+w:String -> Bool
whether a word names a subcommand
def asks_help source · line 57 · raw
@ws:List<&2, String> -> Bool
whether --help stands among the words before the first -- (after it,
every word is a file); the search stops at either
def help_path source · line 66 · raw
@ws:List<&2, String> -> List<&2, String>
the command path --help asks about: the first word other than --help,
when it names a subcommand, else the root's
def line.at source · line 75 · raw
@ask:Bool -> @+ws:List<&2, String> -> List<&2, String>
the line, given whether it asks for --help
def line source · line 84 · raw
@+ws:List<&2, String> -> List<&2, String>
the line shake parses: one that asks for --help is help for its command
path, the page bolt help prints; any other is itself
def spec.files source · line 88 · raw
@+help:String -> 0xa383b26a5a0ef35663b3615d7aedf9e3/main.Arg
the files rest, optional, last among positionals
def version.at source · line 92 · raw
@+rel:String -> @+rev:String -> String
the release, with the short commit in parentheses when it is present
def version source · line 96 · raw
String
the release, and the short commit when the build has one
def spec source · line 100 · raw
0xa383b26a5a0ef35663b3615d7aedf9e3/main.Cli
bolt's program spec
def parse source · line 112 · raw
@av:List<&2, String> -> Result<&2, &2, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched>
argv against bolt's spec
def help_text source · line 116 · raw
@path:List<&2, String> -> String
usage for a command path
def err_text source · line 120 · raw
@e:0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr -> String
a parse error as the text the binary prints
def command source · line 131 · raw
@+name:String -> Cmd
a subcommand by its name; the empty name (no subcommand) is lint
def command.at source · line 137 · raw
@+name:String -> @check:Bool -> Cmd
a subcommand by its name and whether --check was set: fmt takes the
flag, every other name is as command reads it
def files.at source · line 155 · raw
@sel:Maybe<&2, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched> -> @+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> List<&2, String>
the files the selected command bound: each command keeps its own bindings, so they are read from the Matched at the end of the selected path, which is the root's own when no subcommand was selected
def files source · line 163 · raw
@+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> List<&2, String>
the files a successful parse bound, to the command it selected
def checks.at source · line 168 · raw
@sel:Maybe<&2, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched> -> Bool
whether the selected command was given --check: read from its own
Matched, as its files are; no command selected has no such flag
def checks source · line 176 · raw
@+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> Bool
whether a successful parse set --check on the command it selected
def out.run source · line 180 · raw
@ask:Bool -> @+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> Out
a successful parse: the version, or the selected command and its files
def out.fail.at source · line 189 · raw
@asked:Maybe<&2, List<&2, String>> -> @+e:0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr -> Out
a failed parse, given whether it asked for usage: that usage page, or the error
def out.fail source · line 197 · raw
@+e:0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr -> Out
a failed parse: help text, or an error
def out.done source · line 201 · raw
@+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> Out
a successful parse, read once for the version flag
def out source · line 205 · raw
@r:Result<&2, &2, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched> -> Out
what a parse result does