Documentation
¶
Overview ¶
Package flags translates a command segment's Unix-style flag tokens into the typed option values that the underlying gloo-foo/cmd-* constructors expect.
A command declares its flags as a Set of Spec entries (short letter, long name, and either a constant option for boolean flags or a Maker for value-taking flags). Parse walks a segment's arguments against that Set, separating typed options from positionals, and honours short clusters (-lwc), inline values (-n10, --num=5), the GNU "-NUM" shorthand, and "--" long forms. The package holds no knowledge of the REPL or of any specific command; it is the reusable flag-translation layer behind the line domain.
Index ¶
- func AtoiArg(value Argument) (int, error)
- func FirstOr(positional Argv, def Default) string
- func IntList(value Argument) ([]int, error)
- func NumArg(value Argument) (any, error)
- func RangeArg(value Argument) (lo, hi int, err error)
- type Argument
- type Argv
- type Default
- type LongFlag
- type Maker
- type Set
- type ShortFlag
- type Spec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Argv ¶
type Argv []Argument
Argv is the ordered argument list of one command segment.
func Parse ¶
Parse splits args into typed flag options and positional arguments using the command's flag table.
type Default ¶
type Default string
Default is the fallback argument value a command uses when no positional was supplied (e.g. "." as the implicit path of ls and find).
type LongFlag ¶
type LongFlag string
LongFlag is a flag's long name, without its dashes (the "num" of "--num").
type Maker ¶
Maker converts a flag's string value into the typed option value that the underlying cmd-* constructor expects (e.g. "10" into head.HeadLines(10)).
func Int64Maker ¶
Int64Maker builds a value-flag Maker for an int64-typed option.
type ShortFlag ¶
type ShortFlag string
ShortFlag is a flag's single-letter short name, without its dash (the "n" of "-n").
type Spec ¶
type Spec struct {
// contains filtered or unexported fields
}
Spec declares one command flag: its short letter (without dash), its long name (without dashes), and either a constant option (boolean flags) or a maker (value-taking flags). A numeric spec has no short or long name; it captures a bare "-NUM" token (the GNU head/tail shorthand) through its maker.