~/bend-docscommunity

src/args.bend checks

raw source on the hub · import bolt@1.65.0.0/src/args.bend as Args

src/args: bolt's command line, parsed by shake, in ruff's shape: bolt check [file..], bolt format [--check] [file..], bolt lsp, bolt --version. A rest positional on check and format takes every leftover word. The root takes no files: bolt with no command prints the usage to stderr and exits 2, as ruff does, so a lint step that forgot its command fails instead of passing. 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 122 · raw

Data

a subcommand; format carries whether it only checks

type Stream source · line 137 · raw

Data

where a line that stops puts its text

type Out source · line 144 · 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)

Definitions

def widen source · line 29 · 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 38 · 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 46 · raw

IO(List<&2, String>)

bolt's command line: its arguments, without the program

def is_cmd source · line 52 · 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 110 · raw

@av:List<&2, String> -> Result<&2, &2, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched>

argv against bolt's spec

def help_text source · line 114 · raw

@path:List<&2, String> -> String

usage for a command path

def err_text source · line 118 · raw

@e:0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr -> String

a parse error as the text the binary prints

def command source · line 128 · raw

@+name:String -> Cmd

a subcommand by its name: lsp, or else check

def command.at source · line 133 · raw

@+name:String -> @check:Bool -> Cmd

a subcommand by its name and whether --check was set: format takes the flag, every other name is as command reads it

def files.at source · line 151 · 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 159 · raw

@+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> List<&2, String>

the files a successful parse bound, to the command it selected

def checks.at source · line 164 · 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 172 · raw

@+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> Bool

whether a successful parse set --check on the command it selected

def out.go source · line 177 · raw

@path:List<&2, String> -> @+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> Out

a successful parse given the command path it selected: the usage on stderr and exit 2 when it selected none, else that command over its files

def out.run source · line 185 · raw

@ask:Bool -> @+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> Out

a successful parse: the version, or what its command path does

def out.fail.at source · line 194 · 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 202 · raw

@+e:0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr -> Out

a failed parse: help text, or an error

def out.done source · line 206 · raw

@+m:0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched -> Out

a successful parse, read once for the version flag

def out source · line 210 · raw

@r:Result<&2, &2, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched> -> Out

what a parse result does