std/flag
Index
type Int
type Uint
type Float
type Bool
type String
trait Common
struct Flag[T]
fn Name(*self): string
fn What(*self): string
fn Reset(mut *self)
fn Short(*self): rune
struct Set
fn New(): &Set
fn FindFlag(mut *self, name: string): Common
fn FindFlagShort(mut *self, name: rune): Common
fn Flags(mut *self): []Common
fn Parse(mut *self, args: []string)!: []string
fn Reset(mut *self)
fn Add[T: i64 | u64 | f64 | bool | string](mut *self, name: string, short: rune, default: T, what: string): &T
fn AddVar[T: i64 | u64 | f64 | bool | string](mut *self, mut var: &T, name: string, short: rune, what: string)
Int
type Int = &Flag[i64]Flag for i64 type.
Uint
type Uint = &Flag[u64]Flag for u64 type.
Float
type Float = &Flag[f64]Flag for f64 type.
Bool
type Bool = &Flag[bool]Flag for bool type.
String
type String = &Flag[string]Flag for string type
Common
trait Common {
// Returns name of flag.
fn Name(*self): string
// Returns short name of flag.
fn Short(*self): rune
// Returns description of flag.
fn What(*self): string
// 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
Common
Name
fn Name(*self): stringWhat
fn What(*self): stringReset
fn Reset(mut *self)Short
fn Short(*self): runeSet
struct Set {
// 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
fn New(): &SetReturns new flagset.
FindFlag
fn FindFlag(mut *self, name: string): CommonReturns flag by name, returns nil if not exist.
FindFlagShort
fn FindFlagShort(mut *self, name: rune): CommonReturns flag by short name, returns nil if not exist.
Flags
fn Flags(mut *self): []CommonReturns all flags.
Parse
fn Parse(mut *self, args: []string)!: []stringParse arguments and process flags. Returns non-flag content. Error is always string and holds error message.
Reset
fn Reset(mut *self)Resets all flags to default value.
Add
fn Add[T: i64 | u64 | f64 | bool | string](mut *self, name: string, short: rune, default: T, what: string): &TAdds 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 | string](mut *self, mut var: &T, name: string, short: rune, what: string)Same with the Add method but do not allocates new reference, uses existing.