~/bend-docscommunity

src/share/args.bend checks

raw source on the hub · import 0x74799d3f846634a3d7461d4336d7c9d4/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. A compiled binary's runtime keeps --threads N, --gpu V, --gpu-build and --bend-help for itself and strips them wherever they appear, the first two with the value after them; the last two answer and exit before the program starts. The first -- is dropped and everything after it reaches the program untouched, those four included. --help is the program's since 2.0.29, and ez reads it as a request for help (ez/line.bend).

1 import
import Base

Definitions

def nonempty source · line 14 · raw

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

the non-empty strings

def text_of source · line 23 · raw

@res:Result<&1, &1, Pair(U32, String), String> -> String

a variable's text; unset, ""

def copy source · line 32 · 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 41 · 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 50 · 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 60 · 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 68 · raw

IO(List<&2, String>)

every argument after the program's own name, each one readable twice

def run.line source · line 75 · raw

@+entry:String -> @as:List<&2, String> -> List<&2, String>

the command ez run starts: bend on the entry, with every word after run (EZ-TOOL-9)

def drop source · line 79 · 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 89 · 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 99 · 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 108 · 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 113 · 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 118 · 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 124 · 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 132 · raw

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

whether this line is tool run

def argv.tool source · line 136 · 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 144 · 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 153 · 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.