src/ez/line.bend checks
raw source on the hub · import ezx@1.18.0.0/src/ez/line.bend as Line
ez/line: the command line, taken apart before any command runs. spec is
the program, command names what a matched path runs, and line decides
how a parse ends: a command runs, help is shown, or the line is misused.
All of it is pure, so the status a line exits with before any command runs
is a law (laws/ExitStatusSaysFailure.bend); ez/app.bend prints and exits
as line and status say, and runs the command a line names, whose own
end decides the rest.
Trusted, not proved: command-line parsing is correct: parse binds a line
as shake's spec says, help_path names a request for help and only one,
path_of and at follow the selected path, and get, on and help
read and render it. Proved in shake v0.6.0, the rev ez.toml pins (shake's
laws/BindingsComeFromWords.bend, PositionalsBindInOrder,
RestTakesRemainingWords, SubcommandSelects, ChoicesRestrictValues,
DefaultsFillUnbound, RequiredMustBind, HelpWordAsksForHelp,
FailureIsFinal, RepeatsRefusedManyCollects, GetReadsOwnBindings,
SubcommandResultsNavigate, HelpFollowsPath, ErrTextEmptyForRequests and
ErrTextShowsUsage); ez imports only its interface, main.bend, and its
gate does not re-check it. In particular ez help <path> with a word that
names no command there fails as Unexpected, not as a request for help,
and a bare --help before any positional of the command is a request for
help as help is (shake's laws/HelpWordAsksForHelp.bend).
2 imports
import Base import shake@0.9.0.0/main.bend as Shake
Types
type Sub source · line 27 · raw
Data
a subcommand
CInitSub
CAddSub
CRemoveSub
CLockSub
CFetchSub
CCheckSub
CBuildSub
CRunSub
CPublishSub
CTestSub
CProveSub
CDoctorSub
CToolSyncSub
CToolRunSub
CToolInstallSub
CToolUpgradeSub
CHelpSub
type Line source · line 178 · raw
Data
a command runs, with what the line bound for it; help is shown, on stdout; or the line is misused, and says so on stderr
Runs@sub:Sub -> @matched:0x64697f57fea19681b5fa4f87014ce63d/main.Matched -> Line
Shows@text:String -> Line
Misuse@text:String -> Line
type Status source · line 226 · raw
Data
the status a line exits with, when it is decided here, or the command's own end (laws/ExitStatusSaysFailure.bend)
Exits@code:U32 -> Status
EndsStatus
Definitions
def spec.init source · line 47 · raw
0x64697f57fea19681b5fa4f87014ce63d/main.Sub
ez init: a name, an entry and the one-line description
def spec.add source · line 57 · raw
0x64697f57fea19681b5fa4f87014ce63d/main.Sub
ez add: a target, its ref and entry, and the name to record it under
def spec.lock source · line 70 · raw
0x64697f57fea19681b5fa4f87014ce63d/main.Sub
ez lock: --upgrade and the one package it may be limited to
def spec.tool.target source · line 80 · raw
@+name:String -> @+about:String -> 0x64697f57fea19681b5fa4f87014ce63d/main.Sub
a tool subcommand that names a target and may name the entry to build
def spec.tool source · line 90 · raw
0x64697f57fea19681b5fa4f87014ce63d/main.Sub
ez tool: the group, with sync and the three that take a target
def spec source · line 100 · raw
0x64697f57fea19681b5fa4f87014ce63d/main.Cli
the program: every command, and the flags and positionals it binds
def command source · line 129 · raw
@+name:String -> Sub
a subcommand by its path, the words joined with /. A path that names no
command, the empty one of a bare ez or a group such as tool, is CHelp.
def is.help source · line 151 · raw
@sub:Sub -> Bool
whether a subcommand is the one that names no command
def path source · line 159 · raw
@matched:0x64697f57fea19681b5fa4f87014ce63d/main.Matched -> String
the path a match names, its words joined with /
def leaf source · line 166 · raw
@+matched:0x64697f57fea19681b5fa4f87014ce63d/main.Matched -> 0x64697f57fea19681b5fa4f87014ce63d/main.Matched
the Matched of the command the path names, whose bindings are the ones the
line made for that command (shake's laws/SubcommandResultsNavigate.bend:
at(m, path_of(m)) follows the selected path). A None here would be a
Matched parse never answers.
def get source · line 170 · raw
@found:0x64697f57fea19681b5fa4f87014ce63d/main.Matched -> @+name:String -> String
the value the command bound to name, or "" when it bound none
def line.err source · line 186 · raw
@help:Maybe<&2, List<&2, String>> -> @+app:0x64697f57fea19681b5fa4f87014ce63d/main.Cli -> @err:0x64697f57fea19681b5fa4f87014ce63d/main.ParseErr -> Line
a line Shake would not parse: a request for help, whose path Shake has
already checked word by word (shake's laws/HelpWordAsksForHelp.bend: help
bogus fails as Unexpected, not as a request for help), or a usage error
def line.group source · line 197 · raw
@bare:Bool -> @+app:0x64697f57fea19681b5fa4f87014ce63d/main.Cli -> @+matched:0x64697f57fea19681b5fa4f87014ce63d/main.Matched -> Line
a path that names no command: a bare ez is help, as a bare cargo is,
and a bare group such as ez tool is a line that did not say which of its
commands to run, as cargo report with no command is, so its help goes to
stderr and the line fails
def line.run source · line 205 · raw
@help:Bool -> @sub:Sub -> @+app:0x64697f57fea19681b5fa4f87014ce63d/main.Cli -> @+matched:0x64697f57fea19681b5fa4f87014ce63d/main.Matched -> Line
a line Shake parsed: the command its path names runs, or it names none
def line source · line 213 · raw
@+app:0x64697f57fea19681b5fa4f87014ce63d/main.Cli -> @parsed:Result<&2, &2, 0x64697f57fea19681b5fa4f87014ce63d/main.ParseErr, 0x64697f57fea19681b5fa4f87014ce63d/main.Matched> -> Line
how a line ends, from what Shake made of it
def status source · line 231 · raw
@how:Line -> Status
help exits 0, a misused line 1, and a command that runs ends as it ends