~/bend-docscommunity

src/args.bend checks

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

src/args: bolt's command line, parsed by shake. bolt [lint] [file..], bolt 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 119 · raw

Data

a subcommand

type Stream source · line 130 · raw

Data

where a line that stops puts its text

type Out source · line 137 · 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 27 · 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 36 · raw

@ss: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 44 · raw

IO(List<&2, String>)

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

def is_cmd source · line 50 · raw

@+ww:String -> Bool

whether a word names a subcommand

def asks_help source · line 55 · 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 64 · 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 73 · raw

@ask:Bool -> @+ws:List<&2, String> -> List<&2, String>

the line, given whether it asks for --help

def line source · line 82 · 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 86 · raw

@+help:String -> 0xa383b26a5a0ef35663b3615d7aedf9e3/main.Arg

the files rest, optional, last among positionals

def version.at source · line 90 · raw

@+rel:String -> @+rev:String -> String

the release, with the short commit in parentheses when it is present

def version source · line 94 · raw

String

the release, and the short commit when the build has one

def spec source · line 98 · raw

0xa383b26a5a0ef35663b3615d7aedf9e3/main.Cli

bolt's program spec

def parse source · line 107 · raw

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

argv against bolt's spec

def help_text source · line 111 · raw

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

usage for a command path

def err_text source · line 115 · raw

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

a parse error as the text the binary prints

def command source · line 125 · raw

@+name:String -> Cmd

a subcommand by its name; the empty name (no subcommand) is lint

def files.at source · line 144 · raw

@sel:Maybe<&2, 0xa383b26a5a0ef35663b3615d7aedf9e3/main.Matched> -> @+mm: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 152 · raw

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

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

def out.run source · line 156 · raw

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

a successful parse: the version, or the selected command and its files

def out.fail.at source · line 165 · raw

@asked:Maybe<&2, List<&2, String>> -> @+ee:0xa383b26a5a0ef35663b3615d7aedf9e3/main.ParseErr -> Out

a failed parse, given whether it asked for usage: that usage page, or the error

def out.fail source · line 173 · raw

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

a failed parse: help text, or an error

def out.done source · line 177 · raw

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

a successful parse, read once for the version flag

def out source · line 181 · raw

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

what a parse result does