InitError
pub enum InitError = { OutOfMemory }Errors reported while creating a flag set.
Variants
OutOfMemory
pub enum InitError = { OutOfMemory }Errors reported while creating a flag set.
OutOfMemorypub union ParseError = { HelpRequested() | UnknownFlag(ref u8) | MissingValue(ref u8) | InvalidValue(ref u8, ref u8) }Errors reported while parsing arguments.
HelpRequested()UnknownFlag(ref u8)MissingValue(ref u8)InvalidValue(ref u8, ref u8)union FlagValue = { Bool(mut ref bool) | Str(mut ref ref u8) | Int(mut ref i64) | Float(mut ref f64) }The value storage for one registered flag.
Bool(mut ref bool)Str(mut ref ref u8)Int(mut ref i64)Float(mut ref f64)type Flag = { next: mut ref Flag, name: mut ref u8, alias: mut ref u8, help: mut ref u8, placeholder: mut ref u8, default_text: mut ref u8, value: mut FlagValue }One registered flag.
| Name | Type |
|---|---|
next | mut ref Flag |
name | mut ref u8 |
alias | mut ref u8 |
help | mut ref u8 |
placeholder | mut ref u8 |
default_text | mut ref u8 |
value | mut FlagValue |
pub type FlagSet = { name: mut ref u8, description: mut ref u8, head: mut ref Flag, tail: mut ref Flag, positional: mut ref list[ref u8], allow_double_dash: mut bool }A collection of flags and the arguments left over after parsing.
| Name | Type |
|---|---|
name | mut ref u8 |
description | mut ref u8 |
head | mut ref Flag |
tail | mut ref Flag |
positional | mut ref list[ref u8] |
allow_double_dash | mut bool |
pub fn new(name: ref u8, description: ref u8) result[FlagSet, InitError] = trust { ... }Create an empty flag set. name is shown in the usage text.
pub fn allow_double_dash(fs: mut FlagSet, enabled: bool) voidAccept --name spellings as well as the default -name spelling. Also makes a bare -- terminate flag parsing.
fn add(fs: mut FlagSet, name: ref u8, alias: ref u8, help: ref u8, placeholder: ref u8, default_text: ref u8, value: FlagValue) void = trust { ... }pub fn bool_var(fs: mut FlagSet, name: ref u8, alias: ref u8, target: ref bool, help: ref u8) void = trust { ... }Register a boolean flag. The flag is false until it appears on the command line; an explicit value may be given with : or =.
pub fn string_var(fs: mut FlagSet, name: ref u8, alias: ref u8, target: ref ref u8, help: ref u8) void = trust { ... }Register a string flag. Values are borrowed pointers, not copies.
pub fn int_var(fs: mut FlagSet, name: ref u8, alias: ref u8, target: ref i64, help: ref u8) void = trust { ... }Register a signed integer flag.
pub fn float_var(fs: mut FlagSet, name: ref u8, alias: ref u8, target: ref f64, help: ref u8) void = trust { ... }Register a floating-point flag.
pub fn parse(fs: FlagSet, argv: list[ref u8]) result[void, ParseError] = trust { ... }Parse command-line arguments. The first entry is treated as the program name and skipped, matching @args() and os.get_args().
Only the first positional -- is special, and only when double-dash support is enabled. Parsing stops at the first error; values already seen remain set.
pub fn args(fs: FlagSet) list[ref u8] = trust { ... }Positional arguments collected by the last call to parse.
pub fn usage(fs: FlagSet) void = trust { ... }Print the generated usage text to stdout.
pub fn usage_err(fs: FlagSet) void = trust { ... }Print the generated usage text to stderr.
pub fn destroy(fs: FlagSet) void = trust { ... }Release the flag set, its registered flags, and the positional argument list. Target values and borrowed strings are not freed.
pub fn is_help(e: ParseError) boolTrue when parse stopped because -h or -help was requested.
pub fn message(e: ParseError) ref u8 = trust { ... }A human-readable message for a parse error. The returned string is heap-allocated.
fn clear_positional(fs: FlagSet) void = trust { ... }fn emit(to_stderr: bool, line: ref u8) void = trust { ... }fn write_usage(fs: FlagSet, to_stderr: bool) void = trust { ... }fn span_equals(span: ref u8, len: i64, other: ref u8) bool = trust { ... }fn find_name(fs: FlagSet, name: ref u8, len: i64) ref Flag = trust { ... }fn find_separator(s: ref u8) i64 = trust { ... }fn value_of(argv: list[ref u8], body: ref u8, sep: i64, i: mut ref i64, argc: i64) ref u8 = trust { ... }fn parse_bool(value: ref u8) option[bool]fn looks_like_int(value: ref u8) bool = trust { ... }fn parse_int(name: ref u8, value: ref u8) result[i64, ParseError] = trust { ... }fn parse_float(name: ref u8, value: ref u8) result[f64, ParseError]fn assert_ok(r: result[void, ParseError]) void