std.args - ZZ
Raw argv + flag parser. Opaque parser handles (Opaque("args")); declare flags, parse, then read. Supports str/int/bool flags, positionals, subcommands, and --help text.
import std.argsGotchas
Section titled “Gotchas”env.set/env.removeare process-wide (POSIX-like) — affect the whole program.env.removeis a total no-op when the key is absent.env.args()returns script args; usestd.argsfor flag parsing.
Purpose
Section titled “Purpose”std.args parses command-line flags: str_flag, int_flag, bool_flag, positional args, subcommands, and --help text. Declare before parse; read after. get_raw() returns raw argv without parsing. Ideal for CLIs with --flag value, --bool, subcommands, and --help text.
Quickstart
Section titled “Quickstart”import std.args
p := ArgsParser.new()p.str_flag("out", "out.txt")p.int_flag("jobs", 4)p.bool_flag("verbose")if p.parse(["--jobs", "8"]) { println(p.get_str("out")) println(p.get_int("jobs")) println(p.get_bool("verbose"))} else { println(p.error())}
println(p.positional(0) ?? "-") // first leftover or "-"println(p.subcommand() ?? "none")println(p.help("myapp")) // --help textif p.was_help() { println("help shown") }Method syntax
Section titled “Method syntax”Parser handles dispatch method calls:
import std.args
func main() -> Result<int, str> { p := ArgsParser.new() p.str_flag("out", "out.txt") if !p.parse(["--out", "a.txt"]) { return .err(p.error()) } println(p.get_str("out")) // "a.txt" return .ok(0)}Production patterns
Section titled “Production patterns”import std.args
func cli(argv: [str]) -> Result<int, str> { p := ArgsParser.new() p.str_flag("config", "config.toml") p.int_flag("port", 8080) p.bool_flag("verbose") if !p.parse(argv) { return .err(p.error()) } if p.was_help() { println(p.help("myapp")) return .ok(0) } println(p.get_str("config")) return .ok(0)}API reference
Section titled “API reference”15 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.
See also
Section titled “See also”std.env— Environment variables and the surrounding host environment.std.process— Spawning, waiting on and signalling child processes.std.log— Log levels, sinks and spans for structured logging.std.sys— Infallible machine information: OS, CPU, memory and uptime.std.path— Pure lexical path manipulation: join, split, extension and normalisation.std.cell— Shared mutable slots for lock-free hand-off between green threads.
Full index: API reference · Standard library