~/bend-docscommunity

src/args.bend checks

raw source on the hub · import 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/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 arguments through; the runtime takes only its own out of the line (--threads, --gpu, --gpu-build, --bend-help), wherever they stand, and the first --, which hands even those 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 (SPEC.md BOLT-TRUST-8), not bolt's.

5 imports
import Base
import 0xcab8a7a189cec2b51e8db0484f69c593/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 115 · raw

Data

a subcommand

type Stream source · line 126 · raw

Data

where a line that stops puts its text

type Out source · line 133 · 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 23 · 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 32 · 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 40 · raw

IO(List<&2, String>)

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

def is_cmd source · line 46 · raw

@+ww:String -> Bool

whether a word names a subcommand

def asks_help source · line 51 · 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 60 · 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 69 · raw

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

the line, given whether it asks for --help

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

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

the files rest, optional, last among positionals

def version.at source · line 86 · raw

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

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

def version source · line 90 · raw

String

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

def spec source · line 94 · raw

0xcab8a7a189cec2b51e8db0484f69c593/main.Cli

bolt's program spec

def parse source · line 103 · raw

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

argv against bolt's spec

def help_text source · line 107 · raw

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

usage for a command path

def err_text source · line 111 · raw

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

a parse error as the text the binary prints

def command source · line 121 · raw

@+name:String -> Cmd

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

def files.at source · line 140 · raw

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

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

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

def out.run source · line 152 · raw

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

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

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

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

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

def out.fail source · line 169 · raw

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

a failed parse: help text, or an error

def out.done source · line 173 · raw

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

a successful parse, read once for the version flag

def out source · line 177 · raw

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

what a parse result does