flag

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag struct {
	// Alias is an alternative name for a flag, usually shorter :)
	Alias Name

	// ConfigPath is the path from the config to the value the flag updates
	ConfigPath string

	// Envvars holds a list of environment variables to update this flag. Only the first one that exists will be used.
	EnvVars []string

	// EmptyConstructor tells flag how to make a value
	EmptyValueConstructor value.EmptyConstructor

	// HelpShort is a message for the user on how to use this flag
	HelpShort HelpShort

	// Required means the user MUST fill this flag
	Required bool

	// When UnsetSentinal is passed as a flag value, Value is reset and SetBy is set to ""
	UnsetSentinel string

	// IsCommandFlag is set when parsing. Set to true if the flag was attached to a command (as opposed to being inherited from a section)
	IsCommandFlag bool

	// SetBy might be set when parsing. Possible values: appdefault, config, passedflag
	SetBy string

	// Value is set when parsing. Use SetBy != "" to determine whether a value was actually passed  instead of being empty
	Value value.Value
}

func New

func New(helpShort HelpShort, empty value.EmptyConstructor, opts ...FlagOpt) Flag

New creates a Flag with options!

type FlagMap

type FlagMap map[Name]Flag

FlagMap holds flags - used by Commands and Sections

func (FlagMap) AddFlag added in v0.0.13

func (fm FlagMap) AddFlag(name Name, value Flag)

AddFlag adds a new flag and panics if it already exists

func (FlagMap) AddFlags added in v0.0.13

func (fm FlagMap) AddFlags(flagMap FlagMap)

AddFlags adds another FlagMap to this one and and panics if a flag name already exists

func (*FlagMap) SortedNames added in v0.0.13

func (fm *FlagMap) SortedNames() []Name

type FlagOpt

type FlagOpt func(*Flag)

FlagOpt customizes a Flag on creation

func Alias

func Alias(alias Name) FlagOpt

Alias is an alternative name for a flag, usually shorter :)

func ConfigPath

func ConfigPath(path string) FlagOpt

ConfigPath adds a configpath to a flag

func EnvVars

func EnvVars(name ...string) FlagOpt

EnvVars adds a list of environmental variables to search through to update this flag. The first one that exists will be used to update the flag. Further existing envvars will be ignored.

func Required

func Required() FlagOpt

Required means the user MUST fill this flag

func UnsetSentinel added in v0.0.18

func UnsetSentinel(name string) FlagOpt

UnsetSentinel is a bit of an advanced feature meant to allow overriding a default, config, or environmental value with a command line flag. When UnsetSentinel is passed as a flag value, Value is reset and SetBy is set to "". It it recommended to set `name` to "UNSET" for consistency among warg apps. Scalar example:

app --flag UNSET  // undoes anything that sets --flag

Slice example:

app --flag a --flag b --flag UNSET --flag c --flag d // ends up with []string{"c", "d"}

type HelpShort

type HelpShort string

HelpShort is a description of what this flag does.

type Name

type Name string

Name of a flag

Jump to

Keyboard shortcuts

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