Documentation
¶
Index ¶
- func ExtractFlags(args []string, flags map[string]func()) []string
- type Arg
- type Args
- func (a Args) At(v int) string
- func (a Args) AtDefault(v int, fallback string) string
- func (a Args) Empty() bool
- func (a Args) From(start int) Args
- func (a Args) Has(v string) bool
- func (a Args) HasIndex(v int) bool
- func (a Args) IndexOf(v string) int
- func (a Args) Last() string
- func (a Args) Len() int
- func (a Args) LenGt(v int) bool
- func (a Args) LenGte(v int) bool
- func (a Args) LenIs(v int) bool
- func (a Args) LenLt(v int) bool
- func (a Args) LenLte(v int) bool
- func (a Args) Shift() (string, Args)
- func (a Args) Slice(start, end int) Args
- func (a Args) Splice(start, num int) Args
- func (a Args) To(end int) Args
- type FlagSet
- type FlagSets
- func (s *FlagSets) All() *FlagSet
- func (s *FlagSets) Default() *FlagSet
- func (s *FlagSets) Get(name string) *FlagSet
- func (s *FlagSets) Internal() *FlagSet
- func (s *FlagSets) Parse(arguments []string) error
- func (s *FlagSets) ParseAll(arguments []string, fn func(flag *pflag.Flag, value string) error) error
- func (s *FlagSets) Visit(fn func(*pflag.Flag)) Flags
- func (s *FlagSets) VisitAll(fn func(*pflag.Flag)) Flags
- func (s *FlagSets) Visited() Flags
- type Flags
- type Mode
- type Option
- type Readline
- func (a *Readline) AdditionalArgs() Args
- func (a *Readline) AdditionalFlags() Args
- func (a *Readline) AllFlags() []*pflag.Flag
- func (a *Readline) Args() Args
- func (a *Readline) Cmd() string
- func (a *Readline) FlagSets() *FlagSets
- func (a *Readline) Flags() Args
- func (a *Readline) IsModeAdditional() bool
- func (a *Readline) IsModeDefault() bool
- func (a *Readline) Mode() Mode
- func (a *Readline) Parse(input string) error
- func (a *Readline) ParseFlagSets() error
- func (a *Readline) SetFlagSets(fs *FlagSets)
- func (a *Readline) String() string
- func (a *Readline) VisitedFlags() Flags
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractFlags ¶ added in v0.21.0
ExtractFlags consumes a leading run of the given flags off args, invoking each one's handler as it goes, and returns the remaining pass-through args.
It exists for commands that set cobra's DisableFlagParsing, where cobra never populates the flags and so cannot deliver their values. Registering a flag on the root command still matters there - without it cobra rejects the token during command resolution - but registration alone does not read it. This scan is what actually does.
Stopping at the first unrecognized token is load-bearing: everything from the command name onward, including flags meant for the target command (`-n` for kubectl), must reach the plugin untouched. Only a leading run is consumed, so a later occurrence passes through.
args = readline.ExtractFlags(args, map[string]func(){
"--agent": func() { agent.SetFlag(true) },
})
Flag names are matched verbatim, dashes included, so a caller can accept whatever spelling it registered.
Types ¶
type FlagSets ¶ added in v0.4.0
type FlagSets struct {
// contains filtered or unexported fields
}
func NewFlagSets ¶ added in v0.4.0
func NewFlagSets() *FlagSets
type Readline ¶
type Readline struct {
// contains filtered or unexported fields
}