src/share/args.bend checks
raw source on the hub · import ezx@1.14.0.0/src/share/args.bend as Args
share/args: the command line, as the binary itself receives it. Since bend
2.0.32 IO.args() starts with the program as it was invoked, as C's argv
does, so all drops it: the first word left is the subcommand and the rest
are its own. Since 2.0.38 a compiled binary's runtime keeps only its own
bracket: +RTS, -RTS and the words between them (+RTS --threads 4
-RTS), and the first --RTS, after which every word reaches the program
untouched. Every other word is the program's, --, --threads, --gpu,
--gpu-build and --bend-help included (trusted below). --help is the program's since 2.0.29, and ez reads it as
a request for help (ez/line.bend).
Trusted, not proved: the words IO.args hands ez are the process's words
as a program compiled by bend 2.0.38 receives them: every word after the
program's own name, in order and unchanged, except the runtime's. The
runtime's words are +RTS, -RTS and every word between them (a bracket
left open runs to the end), and the first --RTS, after which every word
reaches ez unchanged. Every other word reaches ez, --, --help,
--threads, --gpu, --gpu-build and --bend-help included. What the
runtime hands IO.args is trusted in shake's src/args.bend, at the rev
ez.toml pins, and it was confirmed for ez by running ez compiled by bend
2.0.38: ez +RTS --threads 2 -RTS --help prints ez's help, ez --threads
2 and ez --gpu-build are refused by Shake and exit 1, and ez tool run
<target> --RTS +RTS --threads 2 -RTS a starts the program with +RTS
--threads 2 -RTS a, whose own runtime takes the bracket. It changes when
bend does, so every bend bump rechecks it.
1 import
import Base
Definitions
def nonempty source · line 28 · raw
@ss:List<&2, String> -> List<&2, String>
the non-empty strings
def text_of source · line 37 · raw
@res:Result<&1, &1, Pair(U32, String), String> -> String
a variable's text; unset, ""
def copy source · line 46 · raw
@xs:List<&1, String> -> List<&2, String>
the arguments the process was started with. IO.args() answers a &1 list
and the rest of ez reads its arguments more than once, so the walk copies it.
def split source · line 55 · raw
@xs:List<&2, String> -> Pair(String, List<&2, String>)
the first argument and the ones after it. The pair is returned rather than asked about twice, since a match cannot scrutinise a local binder.
def at source · line 64 · raw
@xs:List<&2, String> -> @index:Nat -> String
the nth argument, or "" when it was not given. Both the list and the count are scrutinised together, so the walk needs no helper to branch through.
def rest source · line 74 · raw
@as:List<&2, String> -> List<&2, String>
every word after the first, which is what run forwards to the entry
def all source · line 82 · raw
IO(List<&2, String>)
every argument after the program's own name, each one readable twice
def run.line source · line 89 · raw
@+entry:String -> @as:List<&2, String> -> List<&2, String>
the command ez run starts: bend on the entry, with every word after
run (laws/RunPassesWords.bend)
def drop source · line 93 · raw
@xs:List<&2, String> -> @count:Nat -> List<&2, String>
n words dropped. What remains when the list runs out first is nothing.
def undash source · line 103 · raw
@xs:List<&2, String> -> List<&2, String>
a leading -- is the separator, not a word the program was given
def tool.lead source · line 113 · raw
@xs:List<&2, String> -> List<&2, String>
the words after tool run with a leading --entry <file> taken off. The
flag comes before the target, as uvx takes its own options before the
command, so every word after the target is the program's.
def tool.rest source · line 122 · raw
@as:List<&2, String> -> List<&2, String>
the words ez tool run forwards: everything after the target, with one
leading -- taken off
def tool.line source · line 127 · raw
@+target:String -> List<&2, String>
tool run with its target, and without the words the program is given.
A missing target is left missing, so the parse can say so.
def tool.flagged source · line 132 · raw
@+file:String -> @+target:String -> List<&2, String>
tool run with its --entry <file> and target, when it has the flag
def tool.parse source · line 138 · raw
@lead:Bool -> @+as:List<&2, String> -> List<&2, String>
the words of tool run the parse reads: the flag when it leads, and the
target
def is.tool.run source · line 146 · raw
@+as:List<&2, String> -> Bool
whether this line is tool run
def argv.tool source · line 150 · raw
@hit:Bool -> @+as:List<&2, String> -> List<&2, String>
tool run parsed as the command and its target; any other line as itself
def argv.run source · line 158 · raw
@hit:Bool -> @+as:List<&2, String> -> List<&2, String>
run parsed as the command alone, so the words it forwards are not flags
def argv.of source · line 167 · raw
@+as:List<&2, String> -> List<&2, String>
a run line and a tool run line are parsed without the words they
forward. Every other line is parsed as it arrived.