flagcodec

package
v0.19.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagToggle = iota
	FlagOption
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Flags

type Flags struct {
	// contains filtered or unexported fields
}

func ParseArgvKeyValue

func ParseArgvKeyValue(args []string, opts ...Option) *Flags

ParseArgvKeyValue parses a clean (trimmed) argv whose components are either toggles or key=value pairs. IOW, this is a restricted and easier to parse flavor of argv on which option and value are guaranteed to be in the same item. IOW, we expect "--opt=foo" AND NOT "--opt", "foo"

func ParseArgvKeyValueWithCommand

func ParseArgvKeyValueWithCommand(command string, args []string) *Flags

ParseArgvKeyValueWithCommand parses a clean (trimmed) argv whose components are either toggles or key=value pairs. IOW, this is a restricted and easier to parse flavor of argv on which option and value are guaranteed to be in the same item. IOW, we expect "--opt=foo" AND NOT "--opt", "foo" The command is supplied explicitly as parameter. DEPRECATED: use ParseArgvValue and WithCommand option

func WithFlagNormalization added in v0.18.2

func WithFlagNormalization(fl *Flags) *Flags

WithFlagNormalization optionally enables flag normalization. The canonical representation of flags in this package is: * single-dash for one-char flags (-v, -h) * double-dash for multi-char flags (--foo, --long-option) pflag allows one-char to have one or two dashes. For flagcodec these were different options. When normalization is enabled, though, all flag names are processed to adhere to the canonical representation, so flagcodec will treat `--v` and `-v` to be the same flag. Since this is possibly breaking change, this treatment is opt-in.

func (*Flags) Args

func (fl *Flags) Args() []string

func (*Flags) Argv

func (fl *Flags) Argv() []string

func (*Flags) Command

func (fl *Flags) Command() string

func (*Flags) Delete

func (fl *Flags) Delete(name string)

func (*Flags) GetFlag

func (fl *Flags) GetFlag(name string) (Val, bool)

func (*Flags) SetOption

func (fl *Flags) SetOption(name, data string)

func (*Flags) SetToggle

func (fl *Flags) SetToggle(name string)

type Option added in v0.18.2

type Option func(*Flags) *Flags

func WithCommand added in v0.18.2

func WithCommand(command string) Option

type Val

type Val struct {
	Kind int
	Data string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL