Documentation ¶
Index ¶
- Constants
- Variables
- type Cmd
- func (c *Cmd) AddArgsCommand(alias ...string) *CmdExecutor
- func (c *Cmd) AddCommand(cmdName string, alias ...string) *CmdExecutor
- func (c *Cmd) Execute(s string) error
- func (c *Cmd) ExecuteArgs() error
- func (c *Cmd) ParseLine(l string) (tokens []CmdToken, err error)
- func (c *Cmd) Printf(fmt string, val ...interface{})
- func (c *Cmd) SetLogger(loggerWriter LoggerWriter) LoggerWriter
- type CmdContext
- type CmdExecutor
- func (ctx *CmdExecutor) AddFlag(name string, valueInfo string, pattern interface{}, flags int, desc string) *CmdExecutor
- func (ctx *CmdExecutor) AddFlagGroup(name string, valueInfo string, pattern interface{}, flags int, desc string, ...) *CmdExecutor
- func (ctx *CmdExecutor) AddFlagParam(name string, valueInfo string, pattern interface{}, flags int, desc string) *CmdExecutor
- func (ctx *CmdExecutor) AddParam(name string, valueInfo string, pattern interface{}, flags int, desc string) *CmdExecutor
- func (ctx *CmdExecutor) E(info ...interface{})
- func (ctx *CmdExecutor) Finish(handler func(ctx CmdContext)) error
- func (ctx *CmdExecutor) Flag(name string) (CmdFlag, error)
- func (ctx *CmdExecutor) Flags() []CmdFlag
- func (ctx *CmdExecutor) I(info ...interface{})
- func (ctx *CmdExecutor) ListCommands(filter func(string) bool)
- func (ctx *CmdExecutor) Param(name string) (CmdParam, error)
- func (ctx *CmdExecutor) ParamSet(name string) ([]CmdParam, error)
- func (ctx *CmdExecutor) Params() []CmdParam
- func (ctx *CmdExecutor) Print(str ...interface{})
- func (ctx *CmdExecutor) Printf(fmt string, args ...interface{})
- func (ctx *CmdExecutor) SetDesc(desc string) *CmdExecutor
- func (ctx *CmdExecutor) ShowUsage(brief bool)
- func (ctx *CmdExecutor) V(info ...interface{})
- func (ctx *CmdExecutor) W(info ...interface{})
- type CmdFlag
- type CmdName
- type CmdParam
- type CmdToken
- type LoggerWriter
Constants ¶
View Source
const ( CmdTypeName = iota CmdTypeFlag CmdTypeParam )
View Source
const ( // ParamRequired the parameter was required. missing this parameter will cause error! ParamRequired = 1 << iota // ParamSet the parameter can be occurs multiply times ParamSet // ParamKeyValuePair the parameter should in KEY=VALUE form ParamKeyValuePair // FlagRequired the flag was required FlagRequired // FlagValueRequired the flag requests a value parameter FlagValueRequired )
Variables ¶
View Source
var ( ErrNoFlag = misc.MakeError("No such flag!") ErrNoParam = misc.MakeError("No such parameter!") ErrIncorrectFlagValue = misc.MakeError("Incorrect flag value!") ErrIncorrectParamValue = misc.MakeError("Incorrect parameter!") ErrGroupFlagsConflict = misc.MakeError("Group flags conflict!") ErrMissingFlag = misc.MakeError("Missing flag!") ErrMissingParameter = misc.MakeError("Missing parameter!") ErrTooManyParameters = misc.MakeError("Too many parameters!") ErrUnknownFlag = misc.MakeError("Unknown flag!") ErrInternalError = misc.MakeError("Internal Error!") ErrFlagValueRequired = misc.MakeError("Flag value required!") )
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
type Cmd struct {
// contains filtered or unexported fields
}
Cmd command line text parser/executor
func (*Cmd) AddArgsCommand ¶
func (c *Cmd) AddArgsCommand(alias ...string) *CmdExecutor
AddArgsCommand defines command that handle os.Args input
func (*Cmd) AddCommand ¶
func (c *Cmd) AddCommand(cmdName string, alias ...string) *CmdExecutor
func (*Cmd) SetLogger ¶
func (c *Cmd) SetLogger(loggerWriter LoggerWriter) LoggerWriter
type CmdContext ¶
type CmdContext interface { Flag(name string) (CmdFlag, error) Flags() []CmdFlag Param(name string) (CmdParam, error) ParamSet(name string) ([]CmdParam, error) Params() []CmdParam Print(info ...interface{}) Printf(fmt string, args ...interface{}) E(info ...interface{}) W(info ...interface{}) I(info ...interface{}) V(info ...interface{}) ListCommands(func(string) bool) ShowUsage(brief bool) }
type CmdExecutor ¶
type CmdExecutor struct {
// contains filtered or unexported fields
}
func (*CmdExecutor) AddFlag ¶
func (ctx *CmdExecutor) AddFlag(name string, valueInfo string, pattern interface{}, flags int, desc string) *CmdExecutor
func (*CmdExecutor) AddFlagGroup ¶
func (ctx *CmdExecutor) AddFlagGroup(name string, valueInfo string, pattern interface{}, flags int, desc string, groupName string) *CmdExecutor
AddFlagGroup create a new flag group / add a new flag into the named group a group of flags are mutually exclusive, only one flag should occurs in a certain group
func (*CmdExecutor) AddFlagParam ¶
func (ctx *CmdExecutor) AddFlagParam(name string, valueInfo string, pattern interface{}, flags int, desc string) *CmdExecutor
func (*CmdExecutor) AddParam ¶
func (ctx *CmdExecutor) AddParam(name string, valueInfo string, pattern interface{}, flags int, desc string) *CmdExecutor
func (*CmdExecutor) E ¶
func (ctx *CmdExecutor) E(info ...interface{})
func (*CmdExecutor) Finish ¶
func (ctx *CmdExecutor) Finish(handler func(ctx CmdContext)) error
func (*CmdExecutor) Flags ¶
func (ctx *CmdExecutor) Flags() []CmdFlag
func (*CmdExecutor) I ¶
func (ctx *CmdExecutor) I(info ...interface{})
func (*CmdExecutor) ListCommands ¶
func (ctx *CmdExecutor) ListCommands(filter func(string) bool)
func (*CmdExecutor) Params ¶
func (ctx *CmdExecutor) Params() []CmdParam
func (*CmdExecutor) Print ¶
func (ctx *CmdExecutor) Print(str ...interface{})
func (*CmdExecutor) Printf ¶
func (ctx *CmdExecutor) Printf(fmt string, args ...interface{})
func (*CmdExecutor) SetDesc ¶
func (ctx *CmdExecutor) SetDesc(desc string) *CmdExecutor
func (*CmdExecutor) ShowUsage ¶
func (ctx *CmdExecutor) ShowUsage(brief bool)
func (*CmdExecutor) V ¶
func (ctx *CmdExecutor) V(info ...interface{})
func (*CmdExecutor) W ¶
func (ctx *CmdExecutor) W(info ...interface{})
type LoggerWriter ¶
type LoggerWriter func(level string, str ...interface{})
Click to show internal directories.
Click to hide internal directories.