Axle v0.17.0
Package

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

TypeMethod and description
bool
__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 and
is argParseOption's question, not this one.
i64
__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 let
the two disagree.
bool
argParseFlag(name : string) : bool 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).
string
argParseOption(name : string) : string Lookup --name <value> or --name=value. Returns the value
if found, "" otherwise. Caller distinguishes "missing" from
"set to empty" via argHasOption.
bool
argHasOption(name : string) : bool True iff the option --name is present (in either the
--name value or --name=value form), disambiguating a value
of "" from an absent option.
i32
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

__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 and
is argParseOption's question, not this one.

Parameters
arg argv token under test
name flag name, written without the leading dashes

#__joinedPrefixBytes

__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 let
the two disagree.

Parameters
arg argv token under test
name option name, written without the leading dashes

#argParseFlag

argParseFlag(name : string) : bool

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).

Parameters
name flag name, written without the leading dashes

#argParseOption

argParseOption(name : string) : string

Lookup --name <value> or --name=value. Returns the value
if found, "" otherwise. Caller distinguishes "missing" from
"set to empty" via argHasOption.

Parameters
name option name, written without the leading dashes

#argHasOption

argHasOption(name : string) : bool

True iff the option --name is present (in either the
--name value or --name=value form), disambiguating a value
of "" from an absent option.

Parameters
name option name, written without the leading dashes

#argFirstPositional

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.