std/args
Raw CLI argument access.
milo
from "std/args" import { args, getFlag, hasFlag }Example
milo
if hasFlag("verbose") {
print("verbose on")
}
match getFlag("output") {
Some(path) => print($"Writing to {path}"),
None => print("Writing to stdout"),
}getFlag reads the --name value form only; --name=value is not recognised. For anything richer, use std/argparse.
API reference
args
milo
pub fn args(): Vec<string>Return all command-line arguments as a Vec<string>. Index 0 is the program name. Recorded and replayed under MILO_RECORD / MILO_REPLAY (std/replay); payload is each argument followed by a NUL.
getFlag
milo
pub fn getFlag(name: &string): string?Get the value following a --name flag. None if the flag is absent or is the last argument. Only the --name value form is recognised, not --name=value. Example: getFlag("port") returns the value after --port.
hasFlag
milo
pub fn hasFlag(name: &string): boolCheck if a --name flag is present in the arguments.