Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A custom flag for TriState Values

License

NotificationsYou must be signed in to change notification settings

tep/flags-tristate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

tristate.go

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 (*TriState)Bool

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 (*TriState)Get

func (ts*TriState)Get()interface{}

Get implements flag.Getter

func (*TriState)Set

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 (TriState)String

func (tsTriState)String()string

String contributes to the implementation of pflag.Value

func (*TriState)Type

func (ts*TriState)Type()string

Type contributes to the implementation of pflag.Value

About

A custom flag for TriState Values

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp