Documentation
¶
Index ¶
- func NewFlag(target any) *flagMaker
- func NewUnaryOption(u UnaryUnmarshaler) *unaryOptionMaker
- func SetUnaryDefault(p Param, s string)
- type AfterParseParamFunc
- type Args
- type BuiltinUnaryUnmarshaler
- type Choice
- type Choices
- type Command
- type Context
- type ContextFunc
- type ExitCoder
- type Flag
- type FormHelper
- type HelpCommand
- type HelpWriter
- type LongParser
- type Main
- type MatchResult
- type Matcher
- type Option
- type Param
- type ParamHelp
- type Parser
- type Positional
- type ShortParser
- type Slice
- type String
- type Subcommand
- type Switch
- type TargetHelper
- type UnaryOption
- type UnarySwitch
- type UnaryUnmarshaler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewUnaryOption ¶
func NewUnaryOption(u UnaryUnmarshaler) *unaryOptionMaker
func SetUnaryDefault ¶
Types ¶
type AfterParseParamFunc ¶
type BuiltinUnaryUnmarshaler ¶
type BuiltinUnaryUnmarshaler[T builtinUnaryUnmarshalTarget] struct{}
type Command ¶
type Command struct { // Parameters that can be parsed as matched. Options []Param // Parameters that are parsed in order. Positionals []Param // A function executed after this command is parsed. Parsing is not yet complete, so any actions should be deferred // from this callback. AfterParseFunc AfterParseParamFunc // Action taken if no subcommand is invoked. If there are subcommands, and none is chosen and there is no // DefaultAction, parsing fails. DefaultAction func() error // A human description of what this command does. Desc string }
A Command represents a collection of parameters and behaviour that are parsed together. Some parameters might themselves be Commands that are parsed recursively.
func FromStruct ¶
func FromStruct(target interface{}) (cmd Command)
func (Command) HasSubcommands ¶
type ContextFunc ¶
type ContextFunc func(ctx Context)
type Flag ¶
type Flag struct {
// contains filtered or unexported fields
}
A flag is an optional argument that results in a boolean value. It has a negative form, and can parse from a bound value in the same argument (with '=').
func (Flag) Match ¶
func (f Flag) Match(args Args) (mr MatchResult)
type FormHelper ¶
type FormHelper interface {
Help(*ParamHelp)
}
type HelpCommand ¶
type HelpCommand struct {
// contains filtered or unexported fields
}
func (HelpCommand) AddToCommand ¶
func (me HelpCommand) AddToCommand(cmd *Command)
func (HelpCommand) Help ¶
func (h HelpCommand) Help() ParamHelp
func (HelpCommand) Init ¶
func (h HelpCommand) Init() error
func (HelpCommand) Match ¶
func (h HelpCommand) Match(args Args) MatchResult
func (HelpCommand) Parse ¶
func (h HelpCommand) Parse(args Args) error
type HelpWriter ¶
type HelpWriter struct {
// contains filtered or unexported fields
}
func (HelpWriter) Indented ¶
func (me HelpWriter) Indented() HelpWriter
func (HelpWriter) WriteLine ¶
func (me HelpWriter) WriteLine(s string)
type LongParser ¶
func (LongParser) GotValue ¶
func (me LongParser) GotValue() bool
func (LongParser) Help ¶
func (me LongParser) Help(f *ParamHelp)
func (*LongParser) Match ¶
func (me *LongParser) Match(args Args) bool
type Main ¶
type MatchResult ¶
type Matcher ¶
type Matcher interface { // Should this allow a nil return for no match? Match(args Args) MatchResult }
type Option ¶
type Option[T any] struct { TargetOk *bool TargetValue *T ValueUnmarshaler UnaryUnmarshaler }
func (Option[T]) TargetHelp ¶
func (Option[T]) UnaryUnmarshal ¶
type Param ¶
type Param interface { Satisfied() bool Matcher // This should not be used directly, normally, and instead Parse is called on a match result. // This is used for parsing defaults for example. TODO: Move to Unmarshaler Value and don't // expose here? Parse(args Args) error Subcommand() generics.Option[Command] Help() ParamHelp AfterParse(ctx Context) error Init() error }
type ParamHelp ¶
type ParamHelp struct { Forms []string Description string Values string Default string Options []ParamHelp Subcommand commandHelp }
func (ParamHelp) Print ¶
func (ph ParamHelp) Print(w HelpWriter)
func (ParamHelp) Write ¶
func (me ParamHelp) Write(w HelpWriter)
type Positional ¶
type Positional struct { Value UnaryUnmarshaler Name string Desc string AfterParseFunc AfterParseParamFunc // contains filtered or unexported fields }
func NewPositional ¶
func NewPositional(u UnaryUnmarshaler) *Positional
func (*Positional) AfterParse ¶
func (me *Positional) AfterParse(ctx Context) error
func (*Positional) Help ¶
func (me *Positional) Help() ParamHelp
func (*Positional) Init ¶
func (me *Positional) Init() error
func (*Positional) Match ¶
func (me *Positional) Match(args Args) MatchResult
func (*Positional) Parse ¶
func (me *Positional) Parse(args Args) error
func (*Positional) Satisfied ¶
func (me *Positional) Satisfied() bool
type ShortParser ¶
type ShortParser struct { Short rune CanUnary bool Prefix rune // contains filtered or unexported fields }
func (ShortParser) GotValue ¶
func (me ShortParser) GotValue() bool
func (ShortParser) Help ¶
func (me ShortParser) Help(f *ParamHelp)
func (*ShortParser) Match ¶
func (me *ShortParser) Match(args Args) bool
type Slice ¶
type Slice[T any] struct { Unmarshaler UnaryUnmarshaler // contains filtered or unexported fields }
func (Slice[T]) TargetHelp ¶
func (Slice[T]) UnaryUnmarshal ¶
type Subcommand ¶
func (Subcommand) Help ¶
func (me Subcommand) Help() ParamHelp
func (Subcommand) Match ¶
func (me Subcommand) Match(args Args) MatchResult
func (Subcommand) Parse ¶
func (me Subcommand) Parse(args Args) error
func (Subcommand) Subcommand ¶
func (me Subcommand) Subcommand() generics.Option[Command]
type Switch ¶
type Switch struct { Longs []string Shorts []rune Desc string AfterParseFunc AfterParseParamFunc // contains filtered or unexported fields }
A switch is an option that takes no values and has no negative form.
func (Switch) AfterParse ¶
func (Switch) Match ¶
func (f Switch) Match(args Args) (mr MatchResult)
type TargetHelper ¶
type TargetHelper interface {
TargetHelp() string
}
type UnaryOption ¶
type UnaryOption struct {
// contains filtered or unexported fields
}
func (*UnaryOption) AfterParse ¶
func (me *UnaryOption) AfterParse(Context) error
func (*UnaryOption) Help ¶
func (me *UnaryOption) Help() ParamHelp
func (*UnaryOption) Init ¶
func (me *UnaryOption) Init() error
func (*UnaryOption) Match ¶
func (me *UnaryOption) Match(args Args) MatchResult
func (*UnaryOption) Parse ¶
func (me *UnaryOption) Parse(args Args) error
func (*UnaryOption) Satisfied ¶
func (me *UnaryOption) Satisfied() bool
type UnarySwitch ¶
type UnarySwitch interface {
GotValue() bool
}
type UnaryUnmarshaler ¶
type UnaryUnmarshaler interface { UnaryUnmarshal(s string) error //CurrentValue() string TargetHelp() string Matching() bool }
func AutoUnmarshaler ¶
func AutoUnmarshaler[T any](t *T) (u UnaryUnmarshaler)
Click to show internal directories.
Click to hide internal directories.