std/sys/cli
std/cli — small argv-parsing helpers, in pure Axle.
Layered over the command line the runtime captures once from the
platform — the same vector std/process::argc / argAt report.
Covers the "does the user pass --flag?" / "what value follows
--opt?" cases without pulling clap-equivalent machinery into the
binary.
Only the split of a command line into arguments diverges per OS
(Windows hands a process one UTF-16 string rather than a vector), and
that is resolved once behind std/ffi/runtime's two shims. Everything
here — the two spellings of a flag, the two spellings of an option,
the first-positional walk — is portable text logic and stays Axle.
Lookup is O(argc) — fine for the dozen-arg case typical of
CLI tools. Call argParseFlag / argParseOption once per
flag at startup.
Free functions
| Type | Method and description |
|---|---|
| __isFlagToken(arg : string, name : string) : bool True when arg is exactly --name or -name.Both spellings, and no prefix match: --name=value is an option andis argParseOption's question, not this one. |
| __joinedPrefixBytes(arg : string, name : string) : i64 The byte length of the --name= / -name= prefix arg opens with,or 0 when it opens with neither.One answer for two questions: whether the joined form matched, and where its value starts. Splitting them would walk arg twice and letthe two disagree. |
| argParseFlag(name : string) : bool True iff the argv contains --name or -name as a separatetoken (not as the prefix of a --name=value form — for that,use argParseOption). |
| argParseOption(name : string) : string Lookup --name <value> or --name=value. Returns the valueif found, "" otherwise. Caller distinguishes "missing" from"set to empty" via argHasOption. |
| argHasOption(name : string) : bool True iff the option --name is present (in either the--name value or --name=value form), disambiguating a valueof "" from an absent option. |
| argFirstPositional() : i32 Index of the first argv token that doesn't start with -,after the program name. Useful for "command" subcommand dispatch ( axle build foo.axle → first positional = "build").Returns -1 if none. |
Method detail
#__isFlagToken
True when arg is exactly --name or -name.
Both spellings, and no prefix match: --name=value is an option and
is argParseOption's question, not this one.
arg argv token under testname flag name, written without the leading dashes#__joinedPrefixBytes
The byte length of the --name= / -name= prefix arg opens with,
or 0 when it opens with neither.
One answer for two questions: whether the joined form matched, and
where its value starts. Splitting them would walk arg twice and let
the two disagree.
arg argv token under testname option name, written without the leading dashes#argParseFlag
True iff the argv contains --name or -name as a separate
token (not as the prefix of a --name=value form — for that,
use argParseOption).
name flag name, written without the leading dashes#argParseOption
Lookup --name <value> or --name=value. Returns the value
if found, "" otherwise. Caller distinguishes "missing" from
"set to empty" via argHasOption.
name option name, written without the leading dashes#argHasOption
True iff the option --name is present (in either the--name value or --name=value form), disambiguating a value
of "" from an absent option.
name option name, written without the leading dashes#argFirstPositional
Index of the first argv token that doesn't start with -,
after the program name. Useful for "command" subcommand
dispatch (axle build foo.axle → first positional = "build").
Returns -1 if none.