- Notifications
You must be signed in to change notification settings - Fork0
A custom flag for TriState Values
License
tep/flags-tristate
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
import "toolman.org/flags/tristate"
go get toolman.org/flags/tristate
Package tristate provides a custom TriState flag for use with the alternateflag package github.com/spf13/pflag. A TriState value may take one of threeforms: True, False or None and is most useful when you are, for instance,filtering records based on a current boolean value -- and you need allthree possibilities (e.g. True, False and I Don't Care)
There are 8 separate functions provided for defining a TriState flag withsome combination of the suffixes: "Var", "P", and "FS" each having thefollowing meaning:
Var: Accepts a TriState pointer instead of returning one.P: Also takes a shorthand character for use with a single dashFS: Accepts a *FlagSet where the flag should be added
The "Var" and "P" suffixes follow the common pflag convention. The "FS"suffix is added to allow the use of alternate FlagSets.
- Variables
- func FlagVar(ts *TriState, name string, value TriState, usage string)
- func FlagVarFS(fs *pflag.FlagSet, ts *TriState, name string, value TriState, usage string)
- func FlagVarP(ts *TriState, name, shorthand string, value TriState, usage string)
- func FlagVarPFS(fs *pflag.FlagSet, ts *TriState, name, shorthand string, value TriState, usage string)
- type TriState
- func Flag(name string, value TriState, usage string) *TriState
- func FlagFS(fs *pflag.FlagSet, name string, value TriState, usage string) *TriState
- func FlagP(name, shorthand string, value TriState, usage string) *TriState
- func FlagPFS(fs *pflag.FlagSet, name, shorthand string, value TriState, usage string) *TriState
- func (ts *TriState) Bool() *bool
- func (ts *TriState) Get() interface{}
- func (ts *TriState) Set(s string) error
- func (ts TriState) String() string
- func (ts *TriState) Type() string
var (// CommandLine is the default FlagSet where flags will be added (unless// otherwise specified)CommandLine=pflag.CommandLine)
varErrBadTriStateValue=errors.New("bad tristate value")
ErrBadTriStateValue is returned by Set if if cannot parse its input.
funcFlagVar(ts*TriState,namestring,valueTriState,usagestring)
FlagVar is similar to Flag that also accepts a pointer to TriStatevariable where the flag value should be stored.
funcFlagVarFS(fs*pflag.FlagSet,ts*TriState,namestring,valueTriState,usagestring)
FlagVarFS is similar to FlagVar but accepts a pointer to the FlagSetwhere this flag should be added.
funcFlagVarP(ts*TriState,name,shorthandstring,valueTriState,usagestring)
FlagVarP is the combination of FlagVar and FlagP.
funcFlagVarPFS(fs*pflag.FlagSet,ts*TriState,name,shorthandstring,valueTriState,usagestring)
FlagVarPFS is similar to FlagVarP but accepts a pointer to the FlagSet where this flag should be added.
typeTriStateint
TriState is a TriState Value and may have one of three values: None, False orTrue. Its "zero" value is None.
const (NoneTriState=iotaFalseTrue)
The three possible tristate values
funcFlag(namestring,valueTriState,usagestring)*TriState
Flag defines a tristate.TriState flag with the specified name, defaultvalue and usage string. The return value is the address of a TriState variablethe stores the values of the flag.
funcFlagFS(fs*pflag.FlagSet,namestring,valueTriState,usagestring)*TriState
FlagFS is similar to Flag but accepts a pointer to the FlagSet wherethis flag should be added.
funcFlagP(name,shorthandstring,valueTriState,usagestring)*TriState
FlagP is similar to Flag butl also accepts a shorthand letter to beused after a single dash.
funcFlagPFS(fs*pflag.FlagSet,name,shorthandstring,valueTriState,usagestring)*TriState
FlagPFS is similar to FlagP but accepts a pointer to the FlagSetwhere this flag should be added.
func (ts*TriState)Bool()*bool
Bool returns a pointer to a bool holding the value of ts. If ts is None thenBool returns nil.
func (ts*TriState)Get()interface{}
Get implements flag.Getter
func (ts*TriState)Set(sstring)error
Set the tristate.Value by parsing s according to the following rules:
Value: Strings------ ----------------------------------------------------------True: 1, t, true, y, yesFalse: 0, f, false, n, noNone: -1, u, unknown, e, either, b, both, a, all, none, null, nil
Allstring input is case insensitive. Any string not mentioned above willreturn ErrBadTriStateValue.
Set contributes to the implementation of pflag.Value
func (tsTriState)String()string
String contributes to the implementation of pflag.Value
func (ts*TriState)Type()string
Type contributes to the implementation of pflag.Value
About
A custom flag for TriState Values