Documentation ¶
Index ¶
- Variables
- func Color(value ...Attribute) func(io.Writer, ...interface{})
- func IsTerminal(fd uintptr) bool
- func New(name string) *flipper
- func UnquoteMessage(flag *Flag) (name string, usage string)
- type Adder
- type Attribute
- type BoolContain
- type Cleaner
- type Cleanup
- type Command
- type CommandFunc
- type Commander
- type ErrorHandling
- type Executer
- type ExitStatus
- type Flag
- type FlagSet
- func (f *FlagSet) Arg(i int) string
- func (f *FlagSet) Args() []string
- func (f *FlagSet) Bool(name string, value bool, usage string) *bool
- func (f *FlagSet) BoolContain(d BoolContain, name, key, usage string) BoolContain
- func (f *FlagSet) BoolContainVar(d BoolContain, name, key string, value bool, usage string)
- func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string)
- func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration
- func (f *FlagSet) DurationContain(d StringContain, name, key, usage string) StringContain
- func (f *FlagSet) DurationContainVar(d StringContain, name, key, value, usage string)
- func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string)
- func (f *FlagSet) Float64(name string, value float64, usage string) *float64
- func (f *FlagSet) Float64Contain(d Float64Contain, name, key, usage string) Float64Contain
- func (f *FlagSet) Float64ContainVar(d Float64Contain, name, key string, value float64, usage string)
- func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string)
- func (f *FlagSet) Int(name string, value int, usage string) *int
- func (f *FlagSet) Int64(name string, value int64, usage string) *int64
- func (f *FlagSet) Int64Contain(d Int64Contain, name, key, usage string) Int64Contain
- func (f *FlagSet) Int64ContainVar(d Int64Contain, name, key string, value int64, usage string)
- func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string)
- func (f *FlagSet) IntContain(d IntContain, name, key, usage string) IntContain
- func (f *FlagSet) IntContainVar(d IntContain, name, key string, value int64, usage string)
- func (f *FlagSet) IntVar(p *int, name string, value int, usage string)
- func (f *FlagSet) Lookup(name string) *Flag
- func (f *FlagSet) NArg() int
- func (f *FlagSet) NFlag() int
- func (f *FlagSet) Out() io.Writer
- func (f *FlagSet) Parse(arguments []string) error
- func (f *FlagSet) Parsed() bool
- func (f *FlagSet) RegexContainVar(d StringContain, name, key, usage string, xfn RgxContainBridgeFunc, ...) StringContain
- func (f *FlagSet) RegexVar(name, usage string, xfn RgxBridgeFunc, rawRegexps ...string)
- func (f *FlagSet) Set(name, value string) error
- func (f *FlagSet) SetOut(output io.Writer)
- func (f *FlagSet) String(name string, value string, usage string) *string
- func (f *FlagSet) StringContain(d StringContain, name, key, usage string) StringContain
- func (f *FlagSet) StringContainVar(d StringContain, name, key, value, usage string)
- func (f *FlagSet) StringVar(p *string, name string, value string, usage string)
- func (f *FlagSet) Uint(name string, value uint, usage string) *uint
- func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64
- func (f *FlagSet) Uint64Contain(d Uint64Contain, name, key, usage string) Uint64Contain
- func (f *FlagSet) Uint64ContainVar(d Uint64Contain, name, key string, value uint64, usage string)
- func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string)
- func (f *FlagSet) UintContain(d UintContain, name, key, usage string) UintContain
- func (f *FlagSet) UintContainVar(d UintContain, name, key string, value uint, usage string)
- func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string)
- func (f *FlagSet) Usage(o io.Writer)
- func (f *FlagSet) Var(value Value, name string, usage string)
- func (f *FlagSet) Visit(fn func(*Flag))
- func (f *FlagSet) VisitAll(fn func(*Flag))
- type Flagger
- type Flipper
- type Float64Contain
- type GetterSetter
- type Group
- type Grouper
- type Groups
- type Instructer
- type Int64Contain
- type IntContain
- type Parser
- type RgxBridgeFunc
- type RgxContainBridgeFunc
- type Stater
- type StringContain
- type Uint64Contain
- type UintContain
- type Value
- type Visiter
- type Writer
- type Wuser
Constants ¶
This section is empty.
Variables ¶
var NoColor = !IsTerminal(os.Stdout.Fd())
Functions ¶
func Color ¶
Should work in most terminals. See github.com/mattn/go-colorable for tweaking tips by os.
func IsTerminal ¶
IsTerminal return true if the file descriptor is terminal. see github.com/mattn/go-isatty You WILL want to change this if you are using an os other than a Linux variant.
func New ¶
func New(name string) *flipper
Return a new package default Flipper corresponding to the provided string name.
func UnquoteMessage ¶
Types ¶
type Cleaner ¶
type Cleaner interface { SetCleanup(ExitStatus, ...Cleanup) RunCleanup(ExitStatus, context.Context) int }
An interface for post-command actions.
type Command ¶
type Command interface { Group() string SetGroup(string) Tag() string Priority() int Escapes() bool Use(io.Writer) Execute(context.Context, []string) (context.Context, ExitStatus) Flagger }
An interface for encapsulating a command.
func NewCommand ¶
func NewCommand(group, tag, use string, priority int, escapes bool, cfn CommandFunc, fs *FlagSet) Command
Returns a new Command provided group, tag, use strings, priority integer, a boolean indicating escape (stop processing command for other commands after this command is found, passing the params to the current command instead of going to another command), A CommandFunc to process the command, and a corresponding FlagSet for the Command).
type CommandFunc ¶
A function taking context.Context, and a string slice, returns context.Context and an ExitStatus.
type ErrorHandling ¶
type ErrorHandling int
An integer type representing method for handling errors.
const ( ContinueOnError ErrorHandling = iota // continue on error ExitOnError // exit on error PanicOnError // panic on error )
type ExitStatus ¶
type ExitStatus int
An integer type useful for marking results of commands.
const ( ExitNo ExitStatus = 999 // continue processing commands ExitSuccess ExitStatus = 0 // return 0 ExitFailure ExitStatus = -1 // return -1 ExitUsageError ExitStatus = -2 // return -2 ExitAny ExitStatus = -666 // status for cleaning function setup, never return )
type Flag ¶
type Flag struct { Name string // name as it appears on command line Message string // help message Value Value // value as set DefValue string // default value (as text); for usage message }
A type representing one command line flag
type FlagSet ¶
type FlagSet struct {
// contains filtered or unexported fields
}
A type for handling any number of flags and fulfilling the Flagger interface.
func NewFlagSet ¶
func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet
Creates a new *FlagSet with the string name and the provided error handling.
func (*FlagSet) BoolContain ¶
func (f *FlagSet) BoolContain(d BoolContain, name, key, usage string) BoolContain
func (*FlagSet) BoolContainVar ¶
func (f *FlagSet) BoolContainVar(d BoolContain, name, key string, value bool, usage string)
func (*FlagSet) DurationContain ¶
func (f *FlagSet) DurationContain(d StringContain, name, key, usage string) StringContain
func (*FlagSet) DurationContainVar ¶
func (f *FlagSet) DurationContainVar(d StringContain, name, key, value, usage string)
func (*FlagSet) DurationVar ¶
func (*FlagSet) Float64Contain ¶
func (f *FlagSet) Float64Contain(d Float64Contain, name, key, usage string) Float64Contain
func (*FlagSet) Float64ContainVar ¶
func (f *FlagSet) Float64ContainVar(d Float64Contain, name, key string, value float64, usage string)
func (*FlagSet) Float64Var ¶
func (*FlagSet) Int64Contain ¶
func (f *FlagSet) Int64Contain(d Int64Contain, name, key, usage string) Int64Contain
func (*FlagSet) Int64ContainVar ¶
func (f *FlagSet) Int64ContainVar(d Int64Contain, name, key string, value int64, usage string)
func (*FlagSet) IntContain ¶
func (f *FlagSet) IntContain(d IntContain, name, key, usage string) IntContain
func (*FlagSet) IntContainVar ¶
func (f *FlagSet) IntContainVar(d IntContain, name, key string, value int64, usage string)
func (*FlagSet) RegexContainVar ¶
func (f *FlagSet) RegexContainVar(d StringContain, name, key, usage string, xfn RgxContainBridgeFunc, rawRegexps ...string) StringContain
A contain backed flag processing a regular expression
func (*FlagSet) RegexVar ¶
func (f *FlagSet) RegexVar(name, usage string, xfn RgxBridgeFunc, rawRegexps ...string)
A flag processing a regular expression
func (*FlagSet) StringContain ¶
func (f *FlagSet) StringContain(d StringContain, name, key, usage string) StringContain
func (*FlagSet) StringContainVar ¶
func (f *FlagSet) StringContainVar(d StringContain, name, key, value, usage string)
func (*FlagSet) Uint64Contain ¶
func (f *FlagSet) Uint64Contain(d Uint64Contain, name, key, usage string) Uint64Contain
func (*FlagSet) Uint64ContainVar ¶
func (f *FlagSet) Uint64ContainVar(d Uint64Contain, name, key string, value uint64, usage string)
func (*FlagSet) UintContain ¶
func (f *FlagSet) UintContain(d UintContain, name, key, usage string) UintContain
func (*FlagSet) UintContainVar ¶
func (f *FlagSet) UintContainVar(d UintContain, name, key string, value uint, usage string)
func (*FlagSet) Var ¶
Sets a Value, name string & usage string as a *Flag to be used by the *FlagSet This will panic for duplicate and/or previously defined Flags.
type Flipper ¶
type Flipper interface { Adder Instructer Commander Executer Cleaner }
Flipper is the flag line processor interface.
type Float64Contain ¶
type GetterSetter ¶
type GetterSetter interface { Lookup(string) *Flag Set(string, string) error Var(Value, string, string) }
An interface for gettign & setting flags.
type Group ¶
func NewGroup ¶
Returns a new group provided the string name, priority integer, and any number of Command.
func (*Group) SortCommandsBy ¶ added in v0.1.1
Set the groups sorting parameter. "alpha" indicating alphabetic sorting is the only currently available outside of the default sort by priority.
type Grouper ¶
type Grouper interface { Groups() *Groups GetGroup(string) *Group SetGroup(string, int, ...Command) Flipper }
An interface for grouping commands.
type Instructer ¶
type Instructer interface { SwapInstructer(Instructer) Instruction(context.Context) SubsetInstruction(c ...Command) func(context.Context) Writer }
An interface for providing instruction i.e. writes usage strings.
type Parser ¶
An interface handling flag parsing from a string slice, and returning details of parsing status.
type RgxContainBridgeFunc ¶
type RgxContainBridgeFunc func(string, StringContain, ...*regexp.Regexp) error