std/flag
Index
type IntFlag
type UintFlag
type FloatFlag
type BoolFlag
type StrFlag
trait CommonFlag
struct Flag
fn Name(self): str
fn What(self): str
fn Reset(mut self)
fn Short(self): rune
struct FlagSet
static fn New(): &FlagSet
fn FindFlag(mut self, name: str): CommonFlag
fn FindFlagShort(mut self, name: rune): CommonFlag
fn Flags(mut self): []CommonFlag
fn Parse(mut self, args: []str)!: []str
fn Reset(mut self)
fn Add[T: i64 | u64 | f64 | bool | str](mut self, name: str, short: rune, default: T, what: str): &T
fn AddVar[T: i64 | u64 | f64 | bool | str](mut self, mut var: &T, name: str, short: rune, what: str)
IntFlag
type IntFlag = &Flag[i64]
Flag for i64 type.
UintFlag
type UintFlag = &Flag[u64]
Flag for u64 type.
FloatFlag
type FloatFlag = &Flag[f64]
Flag for f64 type.
BoolFlag
type BoolFlag = &Flag[bool]
Flag for bool type.
StrFlag
type StrFlag = &Flag[str]
Flag for str type
CommonFlag
trait CommonFlag {
// Returns name of flag.
fn Name(self): str
// Returns short name of flag.
fn Short(self): rune
// Returns description of flag.
fn What(self): str
// Resets data to default.
fn Reset(mut self)
}
Common behaviors of flags.
Flag
struct Flag[T] {
// NOTE: contains filtered hidden or unexported fields
}
A Flag for FlagSet.
Implemented Traits
CommonFlag
Name
fn Name(self): str
What
fn What(self): str
Reset
fn Reset(mut self)
Short
fn Short(self): rune
FlagSet
struct FlagSet {
// NOTE: contains filtered hidden or unexported fields
}
Flag parser for command-line arguments.
Syntax:
Long names can be used with double dash (--). Short names can be
used with a single dash (-). When Boolean flags are used, they use
the opposite of their default values. Floating-point values are the
same as the [ParseFloat] function provided by the "std/conv" package.
Decimal, octal, binary and hexadecimal formats are supported for
signed and unsigned integer types. String types accept values directly.
Octal values are represented by starts with 0o or 0 prefix.
Hexadecimal values are represented by starts with 0x prefix.
Binary values are represented by starts with 0b prefix.
A space is required to give a value. When a single dash (-) is used,
all following characters are considered short names and thus collective
use is allowed. If the short name flags used need values, the values
should follow respectively.
New
static fn New(): &FlagSet
Returns new flagset.
FindFlag
fn FindFlag(mut self, name: str): CommonFlag
Returns flag by name, returns nil if not exist.
FindFlagShort
fn FindFlagShort(mut self, name: rune): CommonFlag
Returns flag by short name, returns nil if not exist.
Flags
fn Flags(mut self): []CommonFlag
Returns all flags.
Parse
fn Parse(mut self, args: []str)!: []str
Parse arguments and process flags. Returns non-flag content. Exceptional always is string and holds error message.
Reset
fn Reset(mut self)
Resets all flags to default value.
Add
fn Add[T: i64 | u64 | f64 | bool | str](mut self, name: str, short: rune, default: T, what: str): &T
Adds new flag and returns allocated reference variable. Panics if name or short name is alreadys exist. Zero (0) short names will be ignored. Panics if used unsupported type.
AddVar
fn AddVar[T: i64 | u64 | f64 | bool | str](mut self, mut var: &T, name: str, short: rune, what: str)
Same with the Add method but do not allocates new reference, uses existing.