~/bend-docscommunity

main.bend checks

raw source on the hub · import shake@0.4.0.0/main.bend as Main

shake: a proven command-line argument parser for Bend 2, with subcommands and help.

Describe a program with app, sub, flag, opt, many, pos and rest; parse binds argv against it, and the result is read one command at a time, as clap's: get, get_all and on read a command's own bindings, and sub_name, sub_of, at and path_of reach the subcommands selected under it. help writes the usage page for a command path. For a failed parse, help_path tells a request for help from an error, err_text writes the message and err_path names the command it failed in. check reports a spec that contradicts itself. argv is the process's arguments. This file is the interface: everything under src/ is internal.

4 imports
import Base
import ./src/cli.bend as S
import ./src/args.bend as Args
import ./src/check.bend as K

Definitions

def Cli source · line 19 · raw

Data

a program spec

def Sub source · line 23 · raw

Data

a nested command

def Arg source · line 27 · raw

Data

one argument: a flag, an option, a positional or a rest positional

def Matched source · line 32 · raw

Data

a successful parse, one command at a time: the bindings the command made, and the subcommand selected under it with its own Matched

def ParseErr source · line 36 · raw

Data

a failed parse

def SpecErr source · line 40 · raw

Data

one way a spec contradicts itself

def app source · line 44 · raw

@+name:String -> @+about:String -> @version:Maybe<&2, String> -> @args:List<&2, 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Arg> -> @subs:List<&2, 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Sub> -> 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Cli

a program: name, about, optional version, top-level args and commands

def sub source · line 54 · raw

@+name:String -> @+about:String -> @args:List<&2, 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Arg> -> @subs:List<&2, 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Sub> -> 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Sub

a nested command

def flag source · line 63 · raw

@+name:String -> @short:Maybe<&2, String> -> @long:Maybe<&2, String> -> @+help:String -> 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Arg

a boolean flag

def opt source · line 72 · raw

@+name:String -> @short:Maybe<&2, String> -> @long:Maybe<&2, String> -> @+help:String -> @required:Bool -> @default:Maybe<&2, String> -> @choices:List<&2, String> -> 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Arg

a valued option

def many source · line 85 · raw

@+name:String -> @short:Maybe<&2, String> -> @long:Maybe<&2, String> -> @+help:String -> @required:Bool -> @default:Maybe<&2, String> -> @choices:List<&2, String> -> 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Arg

an option that may be given more than once; get_all reads every value, in order, and get the last

def pos source · line 97 · raw

@+name:String -> @+help:String -> @required:Bool -> @default:Maybe<&2, String> -> @choices:List<&2, String> -> 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Arg

a positional

def rest source · line 107 · raw

@+name:String -> @+help:String -> @required:Bool -> @default:Maybe<&2, String> -> @choices:List<&2, String> -> 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Arg

a rest positional: every leftover word, as one name

def check source · line 121 · raw

@spec:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Cli -> List<&2, 0xcab8a7a189cec2b51e8db0484f69c593/src/check.SpecErr>

every way a spec contradicts itself: a rest positional that is not the last, a repeated argument name or spelling, a repeated subcommand name, a subcommand named help, a default outside its choices, a required positional after an optional one. Empty for a well-formed spec, which is what SPEC.md's parse guarantees are about; parse does not call it

def spec_err_text source · line 125 · raw

@err:0xcab8a7a189cec2b51e8db0484f69c593/src/check.SpecErr -> String

a report of check as one line

def parse source · line 129 · raw

@spec:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Cli -> @words:List<&2, String> -> Result<&2, &2, 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.ParseErr, 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched>

argv against a program spec

def get source · line 133 · raw

@found:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched -> @+name:String -> Maybe<&2, String>

the value this command bound to name last, or None when it bound none

def get_all source · line 137 · raw

@found:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched -> @+name:String -> List<&2, String>

every value this command bound to name, in argv order

def on source · line 141 · raw

@found:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched -> @+name:String -> Bool

whether this command's flag named name was set

def path_of source · line 146 · raw

@found:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched -> List<&2, String>

the names of the subcommands selected below this command, in order: the whole selected path for the Matched parse answers

def sub_name source · line 150 · raw

@found:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched -> Maybe<&2, String>

the name of the subcommand selected under this command, or None

def sub_of source · line 154 · raw

@found:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched -> @+name:String -> Maybe<&2, 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched>

the Matched of subcommand name when it is the one selected, else None

def at source · line 159 · raw

@found:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched -> @path:List<&2, String> -> Maybe<&2, 0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Matched>

the Matched of the command path names below this one, following sub_of name by name, or None where a name is not the one selected

def help source · line 164 · raw

@+spec:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Cli -> @path:List<&2, String> -> String

the usage page for path under spec; an unknown name in the path is skipped

def err_text source · line 169 · raw

@+spec:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.Cli -> @err:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.ParseErr -> String

the message for a failed parse, ending with the root usage line; empty for a request for help, which the caller answers with help

def err_path source · line 174 · raw

@err:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.ParseErr -> List<&2, String>

the command path where the parse failed: the path selected when it did, or for a request for help the path it asks about

def help_path source · line 194 · raw

@err:0xcab8a7a189cec2b51e8db0484f69c593/src/cli.ParseErr -> Maybe<&2, List<&2, String>>

the command path of a request for help (help, help <path>, --help), or None when the parse failed for another reason

def argv source · line 216 · raw

IO(List<&2, String>)

the process's arguments, each word reusable, without the program name that IO.args starts with (bend 2.0.32 and later). A compiled program's runtime has already acted on --bend-help, --gpu-build, --threads N and --gpu X and taken the first --, passing every word after it here unexamined; so the -- that parse sees is the user's second one