flag

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MPL-2.0 Imports: 13 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolPtrVar added in v0.7.0

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

-- BoolPtrVar and boolPtr BoolPtrVar is used to discern between values provided via CLI flags for "true", "false", and "not specified". Because of this there is no default value offered. If you want to use a boolean flag with a default, see flag_bool.go

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) BoolPtrVar added in v0.7.0

func (f *Set) BoolPtrVar(i *BoolPtrVar)

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 (f *Sets) Args() []string

Args returns the remaining args after parsing.

func (*Sets) Completions

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

Completions returns the completions for this flag set.

func (*Sets) Help

func (fs *Sets) Help() string

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

func (*Sets) NewSet

func (f *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 (f *Sets) Parse(args []string) error

Parse parses the given flags, returning any errors.

func (*Sets) Parsed

func (f *Sets) Parsed() bool

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

func (*Sets) Visit

func (f *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 (fs *Sets) VisitSets(fn func(name string, set *Set))

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

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