flag

package
v0.0.0-...-8ac97bf Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package flag is a thin layer over the stdlib flag package that provides some minimal features such as aliasing, autocompletion handling, improved defaults, etc. It was created for mitchellh/cli but can work as a standalone package. Source: https://github.com/hashicorp/waypoint/tree/348d2c77fce199952618ccef6433c8844b22583b/internal/pkg/flag, or release tag 0.5.1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolVar

type BoolVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    bool
	Hidden     bool
	EnvVar     string
	Target     *bool
	Completion complete.Predictor
	SetHook    func(val bool)
}

-- BoolVar and boolValue.

type DurationVar

type DurationVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    time.Duration
	Hidden     bool
	EnvVar     string
	Target     *time.Duration
	Completion complete.Predictor
}

-- DurationVar and durationValue.

type EnumSingleVar

type EnumSingleVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Values     []string
	Default    string
	Hidden     bool
	EnvVar     string
	Target     *string
	SetHook    func(val string)
	Completion complete.Predictor
}

-- EnumVar and enumValue.

type EnumVar

type EnumVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Values     []string
	Default    []string
	Hidden     bool
	EnvVar     string
	Target     *[]string
	Completion complete.Predictor
}

-- EnumVar and enumValue.

type FlagExample

type FlagExample interface {
	Example() string
}

FlagExample is an interface which declares an example value. This is used in help generation to provide better help text.

type FlagVisibility

type FlagVisibility interface {
	Hidden() bool
}

FlagVisibility is an interface which declares whether a flag should be hidden from help and completions. This is usually used for deprecations on "internal-only" flags.

type Float64Var

type Float64Var struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    float64
	Hidden     bool
	EnvVar     string
	Target     *float64
	Completion complete.Predictor
}

-- Float64Var and float64Value.

type Int64Var

type Int64Var struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    int64
	Hidden     bool
	EnvVar     string
	Target     *int64
	Completion complete.Predictor
	SetHook    func(val int64)
}

-- Int64Var and int64Value.

type IntVar

type IntVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    int
	Hidden     bool
	EnvVar     string
	Target     *int
	Completion complete.Predictor
	SetHook    func(val int)
}

-- IntVar and intValue.

type Set

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

Set is a grouped wrapper around a real flag set and a grouped flag set.

func NewSet

func NewSet(name string) *Set

NewSet creates a new flag set.

func (*Set) BoolVar

func (f *Set) BoolVar(i *BoolVar)

func (*Set) DurationVar

func (f *Set) DurationVar(i *DurationVar)

func (*Set) EnumSingleVar

func (f *Set) EnumSingleVar(i *EnumSingleVar)

func (*Set) EnumVar

func (f *Set) EnumVar(i *EnumVar)

func (*Set) Float64Var

func (f *Set) Float64Var(i *Float64Var)

func (*Set) Int64Var

func (f *Set) Int64Var(i *Int64Var)

func (*Set) IntVar

func (f *Set) IntVar(i *IntVar)

func (*Set) Name

func (f *Set) Name() string

Name returns the name of this flag set.

func (*Set) StringMapVar

func (f *Set) StringMapVar(i *StringMapVar)

func (*Set) StringSliceVar

func (f *Set) StringSliceVar(i *StringSliceVar)

func (*Set) StringVar

func (f *Set) StringVar(i *StringVar)

func (*Set) Uint64Var

func (f *Set) Uint64Var(i *Uint64Var)

func (*Set) UintVar

func (f *Set) UintVar(i *UintVar)

func (*Set) Var

func (f *Set) Var(value flag.Value, name, usage string)

Var is a lower-level API for adding something to the flags. It should be used wtih caution, since it bypasses all validation. Consider VarFlag instead.

func (*Set) VarFlag

func (f *Set) VarFlag(i *VarFlag)

func (*Set) Visit

func (f *Set) Visit(fn func(*flag.Flag))

func (*Set) VisitAll

func (f *Set) VisitAll(fn func(*flag.Flag))

func (*Set) VisitVars

func (f *Set) VisitVars(fn func(*VarFlag))

type Sets

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

Sets is a group of flag sets.

func NewSets

func NewSets() *Sets

NewSets creates a new flag sets.

func (*Sets) Args

func (s *Sets) Args() []string

Args returns the remaining args after parsing.

func (*Sets) Completions

func (s *Sets) Completions() complete.Flags

Completions returns the completions for this flag set.

func (*Sets) GetSetFlags

func (s *Sets) GetSetFlags(setName string) []string

GetSetFlags returns a slice of flags for a given set. If the requested set does not exist, this will return an empty slice.

func (*Sets) Help

func (s *Sets) Help() string

Help builds custom help for this command, grouping by flag set.

func (*Sets) NewSet

func (s *Sets) NewSet(name string) *Set

NewSet creates a new single flag set. A set should be created for any grouping of flags, for example "Common Options", "Auth Options", etc.

func (*Sets) Parse

func (s *Sets) Parse(args []string) error

Parse parses the given flags, returning any errors.

func (*Sets) Parsed

func (s *Sets) Parsed() bool

Parsed reports whether the command-line flags have been parsed.

func (*Sets) Visit

func (s *Sets) Visit(fn func(*flag.Flag))

Visit visits the flags in lexicographical order, calling fn for each. It visits only those flags that have been set.

func (*Sets) VisitSets

func (s *Sets) VisitSets(fn func(name string, set *Set))

VisitSets visits each set and performs action based on the passed in function.

type StringMapVar

type StringMapVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    map[string]string
	Hidden     bool
	Target     *map[string]string
	Completion complete.Predictor
}

-- StringMapVar and stringMapValue.

type StringSliceVar

type StringSliceVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    []string
	Hidden     bool
	EnvVar     string
	Target     *[]string
	Completion complete.Predictor
}

-- StringSliceVar and stringSliceValue.

type StringVar

type StringVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    string
	Hidden     bool
	EnvVar     string
	Target     *string
	Completion complete.Predictor
	SetHook    func(val string)
}

-- StringVar and stringValue.

type Uint64Var

type Uint64Var struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    uint64
	Hidden     bool
	EnvVar     string
	Target     *uint64
	Completion complete.Predictor
	SetHook    func(val uint64)
}

-- Uint64Var and uint64Value.

type UintVar

type UintVar struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    uint
	Hidden     bool
	EnvVar     string
	Target     *uint
	Completion complete.Predictor
	SetHook    func(val uint)
}

-- UintVar && uintValue.

type VarFlag

type VarFlag struct {
	Name       string
	Aliases    []string
	Usage      string
	Default    string
	EnvVar     string
	Value      flag.Value
	Completion complete.Predictor
}

-- VarFlag.

Jump to

Keyboard shortcuts

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