Documentation
¶
Overview ¶
Package termi is designed to make processing argument strings from the command line easier and enable nested commands within applications supporting their own different flags.
Index ¶
- Constants
- Variables
- func EnvironmentDescription(obj interface{}) (map[string]string, error)
- type Boolean
- type Duration
- type Flag
- type FlagSet
- type Integer
- type String
- type UnsignedInteger
- func (u *UnsignedInteger) IsFlag(name string) bool
- func (u *UnsignedInteger) Set(value string) error
- func (u *UnsignedInteger) SetDescription(description string) Flag
- func (u *UnsignedInteger) SetName(name string) Flag
- func (u *UnsignedInteger) SetValue(value interface{}) Flag
- func (u *UnsignedInteger) String() string
Constants ¶
const ( EnvironmentTag = "env" DescriptionTag = "description" DefaultDescription = "expects %v as the value" )
Variables ¶
var (
ErrInvalidType = errors.New("incorrect type being used, expected struct or pointer to struct")
)
var ( // ErrorMissingBoolean allows for checking if we need to stumble when parsing flag arguments ErrorMissingBoolean = errors.New("non boolean value parsed") )
Functions ¶
func EnvironmentDescription ¶
EnvironmentDescription fetches struct tags being used in order to print out to flag.Usage or other meaningful parts of the application
Types ¶
type Boolean ¶
type Boolean struct {
// contains filtered or unexported fields
}
Boolean defines an optional flag type which will default to true if the option is missing come parsing time.
func (*Boolean) SetDescription ¶
type Duration ¶ added in v1.0.0
type Duration struct {
// contains filtered or unexported fields
}
func (*Duration) SetDescription ¶ added in v1.0.0
type Flag ¶
type Flag interface { // SetDescription allows you to set the usage of the flag SetDescription(description string) Flag // SetValue allows you to pass the reference to the value you wish to // update with when parse is called. SetValue(value interface{}) Flag // SetName allows you to define what argument is associated with this flag. // Can be called multiple times SetName(name string) Flag // Set is called when parsing the argument within the FlagSet Set(value string) error // IsFlag allows the flag set to parse the command line arg IsFlag(name string) bool }
Flag is a neat little abstraction that allows for simplified Command line arguments
func Must ¶ added in v0.3.0
Must allows for wrapping the generic flag parser to provide simple usage for the lazy developer if the err is not nil, it will panic.
func NewBoolean ¶
func NewBoolean() Flag
func NewDuration ¶ added in v1.0.0
func NewDuration() Flag
func NewFlag ¶ added in v0.3.0
NewFlag is a generic function that will return the correct concrete flag type so that the value will be correctly updated.
func NewInteger ¶
func NewInteger() Flag
func NewUsignedInteger ¶ added in v0.3.0
func NewUsignedInteger() Flag
type FlagSet ¶
type FlagSet interface { // SetDescription allows you to parse a text/template // in order to printed a more meaningful description // By default, the variables are: // - name : name of the application // - GoVersion : the version of go being used // - environments : a map of the variables that can be set by an env // - flags : All the flags defined in the Set SetDescription(description string) // SetEnvironment allows you set parse a variable that is used // to gather environment values at runtime. SetEnvironment(variable interface{}) FlagSet // Register allows you to pass a flag object will be stored with this // Set Register(flag Flag) FlagSet // Parse will read all the strings passed and update flags when applied // then return the unused args. // When "--" is read in the args list, in remaining args will be returned unprocessed // after that point. Parse(args []string) ([]string, error) // ParseEnvironment will gather all environment variables and apply the values // to the stored environment values. ParseEnvironment() error // PrintDescription will print the stored description templated to the given writer. // If nill is passed, this function will exit early. PrintDescription(w io.Writer) error }
FlagSet is my own version of the native 'flag.FlagSet' I felt as though it was missing features, so I am improving it as to how I like it.
func NewFlagSet ¶
func NewFlagSet() FlagSet
type Integer ¶
type Integer struct {
// contains filtered or unexported fields
}
func (*Integer) SetDescription ¶
type String ¶
type String struct {
// contains filtered or unexported fields
}
func (*String) SetDescription ¶
type UnsignedInteger ¶ added in v0.3.0
type UnsignedInteger struct {
// contains filtered or unexported fields
}
func (*UnsignedInteger) IsFlag ¶ added in v0.3.0
func (u *UnsignedInteger) IsFlag(name string) bool
func (*UnsignedInteger) Set ¶ added in v0.3.0
func (u *UnsignedInteger) Set(value string) error
func (*UnsignedInteger) SetDescription ¶ added in v0.3.0
func (u *UnsignedInteger) SetDescription(description string) Flag
func (*UnsignedInteger) SetName ¶ added in v0.3.0
func (u *UnsignedInteger) SetName(name string) Flag
func (*UnsignedInteger) SetValue ¶ added in v0.3.0
func (u *UnsignedInteger) SetValue(value interface{}) Flag
func (*UnsignedInteger) String ¶ added in v0.3.0
func (u *UnsignedInteger) String() string