Documentation ¶
Index ¶
- Constants
- Variables
- type Arg
- type Args
- type ArgsDef
- func (def *ArgsDef) ArgTag(index int, tag string) string
- func (def *ArgsDef) Args() []Arg
- func (def *ArgsDef) Init(outerStructPtr interface{}) error
- func (def *ArgsDef) JSONArgsFunc(commandFunc interface{}, resultsHandlers []ResultsHandler) (JSONArgsFunc, error)
- func (def *ArgsDef) JSONArgsResultValuesFunc(commandFunc interface{}) (JSONArgsResultValuesFunc, error)
- func (def *ArgsDef) MapArgsFunc(commandFunc interface{}, resultsHandlers []ResultsHandler) (MapArgsFunc, error)
- func (def *ArgsDef) MapArgsResultValuesFunc(commandFunc interface{}) (MapArgsResultValuesFunc, error)
- func (def *ArgsDef) NumArgs() int
- func (def *ArgsDef) String() string
- func (def *ArgsDef) StringArgsFunc(commandFunc interface{}, resultsHandlers []ResultsHandler) (StringArgsFunc, error)
- func (def *ArgsDef) StringArgsResultValuesFunc(commandFunc interface{}) (StringArgsResultValuesFunc, error)
- func (def *ArgsDef) StringMapArgsFunc(commandFunc interface{}, resultsHandlers []ResultsHandler) (StringMapArgsFunc, error)
- func (def *ArgsDef) StringMapArgsResultValuesFunc(commandFunc interface{}) (StringMapArgsResultValuesFunc, error)
- type JSONArgsFunc
- type JSONArgsResultValuesFunc
- type Logger
- type MapArgsFunc
- type MapArgsResultValuesFunc
- type PrintlnText
- type ResultsHandler
- type ResultsHandlerFunc
- func LogTo(logger Logger) ResultsHandlerFunc
- func LogWithPrefixTo(prefix string, logger Logger) ResultsHandlerFunc
- func PrintTo(writer io.Writer) ResultsHandlerFunc
- func PrintlnTo(writer io.Writer) ResultsHandlerFunc
- func PrintlnWithPrefix(prefix string) ResultsHandlerFunc
- func PrintlnWithPrefixTo(prefix string, writer io.Writer) ResultsHandlerFunc
- type StringArgsCommandLogger
- type StringArgsCommandLoggerFunc
- type StringArgsDispatcher
- func (disp *StringArgsDispatcher) AddCommand(command, description string, commandFunc interface{}, args Args, ...) error
- func (disp *StringArgsDispatcher) AddDefaultCommand(description string, commandFunc interface{}, args Args, ...) error
- func (disp *StringArgsDispatcher) Dispatch(ctx context.Context, command string, args ...string) error
- func (disp *StringArgsDispatcher) DispatchCombinedCommandAndArgs(ctx context.Context, commandAndArgs []string) (command string, err error)
- func (disp *StringArgsDispatcher) DispatchDefaultCommand() error
- func (disp *StringArgsDispatcher) HasCommnd(command string) bool
- func (disp *StringArgsDispatcher) HasDefaultCommnd() bool
- func (disp *StringArgsDispatcher) MustAddCommand(command, description string, commandFunc interface{}, args Args, ...)
- func (disp *StringArgsDispatcher) MustAddDefaultCommand(description string, commandFunc interface{}, args Args, ...)
- func (disp *StringArgsDispatcher) MustDispatch(ctx context.Context, command string, args ...string)
- func (disp *StringArgsDispatcher) MustDispatchCombinedCommandAndArgs(ctx context.Context, commandAndArgs []string) (command string)
- func (disp *StringArgsDispatcher) MustDispatchDefaultCommand()
- func (disp *StringArgsDispatcher) PrintCommands(appName string)
- func (disp *StringArgsDispatcher) PrintCommandsUsageIntro(appName string, output io.Writer)
- type StringArgsFunc
- type StringArgsResultValuesFunc
- type StringMapArgsFunc
- type StringMapArgsResultValuesFunc
- type SuperCommandNotFound
- type SuperStringArgsDispatcher
- func (disp *SuperStringArgsDispatcher) AddDefaultCommand(description string, commandFunc interface{}, args Args, ...) error
- func (disp *SuperStringArgsDispatcher) AddSuperCommand(superCommand string) (subDisp *StringArgsDispatcher, err error)
- func (disp *SuperStringArgsDispatcher) Dispatch(ctx context.Context, superCommand, command string, args ...string) error
- func (disp *SuperStringArgsDispatcher) DispatchCombinedCommandAndArgs(ctx context.Context, commandAndArgs []string) (superCommand, command string, err error)
- func (disp *SuperStringArgsDispatcher) DispatchDefaultCommand() error
- func (disp *SuperStringArgsDispatcher) HasCommnd(superCommand string) bool
- func (disp *SuperStringArgsDispatcher) HasSubCommnd(superCommand, command string) bool
- func (disp *SuperStringArgsDispatcher) MustAddDefaultCommand(description string, commandFunc interface{}, args Args, ...)
- func (disp *SuperStringArgsDispatcher) MustAddSuperCommand(superCommand string) (subDisp *StringArgsDispatcher)
- func (disp *SuperStringArgsDispatcher) MustDispatch(ctx context.Context, superCommand, command string, args ...string)
- func (disp *SuperStringArgsDispatcher) MustDispatchCombinedCommandAndArgs(ctx context.Context, commandAndArgs []string) (superCommand, command string)
- func (disp *SuperStringArgsDispatcher) MustDispatchDefaultCommand()
- func (disp *SuperStringArgsDispatcher) PrintCommands(appName string)
- func (disp *SuperStringArgsDispatcher) PrintCommandsUsageIntro(appName string, output io.Writer)
Constants ¶
const ( Default = "" ErrNotFound = constError("command not found") )
Variables ¶
var ( // CommandUsageColor is the color in which the // command usage will be printed on the screen. CommandUsageColor = color.New(color.FgHiCyan) // CommandDescriptionColor is the color in which the // command usage description will be printed on the screen. CommandDescriptionColor = color.New(color.FgCyan) ArgNameTag = "arg" ArgDescriptionTag = "desc" // TimeFormats used in that order to try parse time strings. // If a time format has not time zone part, // then the date is returned in the local time zone. TimeFormats = []string{ time.RFC3339Nano, time.RFC3339, "2006-01-02 15:04:05", "2006-01-02 15:04", "2006-01-02", } )
Functions ¶
This section is empty.
Types ¶
type ArgsDef ¶
type ArgsDef struct {
// contains filtered or unexported fields
}
ArgsDef implements Args
var WithoutArgs ArgsDef
func (*ArgsDef) Init ¶
Init initializes ArgsDef with the reflection data from outerStructPtr wich has to be the address of the struct variable that embedds ArgsDef.
func (*ArgsDef) JSONArgsFunc ¶
func (def *ArgsDef) JSONArgsFunc(commandFunc interface{}, resultsHandlers []ResultsHandler) (JSONArgsFunc, error)
func (*ArgsDef) JSONArgsResultValuesFunc ¶
func (def *ArgsDef) JSONArgsResultValuesFunc(commandFunc interface{}) (JSONArgsResultValuesFunc, error)
func (*ArgsDef) MapArgsFunc ¶
func (def *ArgsDef) MapArgsFunc(commandFunc interface{}, resultsHandlers []ResultsHandler) (MapArgsFunc, error)
func (*ArgsDef) MapArgsResultValuesFunc ¶
func (def *ArgsDef) MapArgsResultValuesFunc(commandFunc interface{}) (MapArgsResultValuesFunc, error)
func (*ArgsDef) StringArgsFunc ¶
func (def *ArgsDef) StringArgsFunc(commandFunc interface{}, resultsHandlers []ResultsHandler) (StringArgsFunc, error)
func (*ArgsDef) StringArgsResultValuesFunc ¶
func (def *ArgsDef) StringArgsResultValuesFunc(commandFunc interface{}) (StringArgsResultValuesFunc, error)
func (*ArgsDef) StringMapArgsFunc ¶
func (def *ArgsDef) StringMapArgsFunc(commandFunc interface{}, resultsHandlers []ResultsHandler) (StringMapArgsFunc, error)
func (*ArgsDef) StringMapArgsResultValuesFunc ¶
func (def *ArgsDef) StringMapArgsResultValuesFunc(commandFunc interface{}) (StringMapArgsResultValuesFunc, error)
type JSONArgsFunc ¶
func GetJSONArgsFunc ¶
func GetJSONArgsFunc(commandFunc interface{}, argsStructPtr interface{}, resultsHandlers ...ResultsHandler) (JSONArgsFunc, error)
func MustGetJSONArgsFunc ¶
func MustGetJSONArgsFunc(commandFunc interface{}, argsStructPtr interface{}, resultsHandlers ...ResultsHandler) JSONArgsFunc
type JSONArgsResultValuesFunc ¶
func GetJSONArgsResultValuesFunc ¶
func GetJSONArgsResultValuesFunc(commandFunc interface{}, argsStructPtr interface{}) (JSONArgsResultValuesFunc, error)
func MustGetJSONArgsResultValuesFunc ¶
func MustGetJSONArgsResultValuesFunc(commandFunc interface{}, argsStructPtr interface{}) JSONArgsResultValuesFunc
type MapArgsFunc ¶
func GetMapArgsFunc ¶
func GetMapArgsFunc(commandFunc interface{}, argsStructPtr interface{}, resultsHandlers ...ResultsHandler) (MapArgsFunc, error)
func MustGetMapArgsFunc ¶
func MustGetMapArgsFunc(commandFunc interface{}, argsStructPtr interface{}, resultsHandlers ...ResultsHandler) MapArgsFunc
type MapArgsResultValuesFunc ¶
type MapArgsResultValuesFunc func(ctx context.Context, args map[string]interface{}) ([]reflect.Value, error)
func GetMapArgsResultValuesFunc ¶
func GetMapArgsResultValuesFunc(commandFunc interface{}, argsStructPtr interface{}) (MapArgsResultValuesFunc, error)
func MustGetMapArgsResultValuesFunc ¶
func MustGetMapArgsResultValuesFunc(commandFunc interface{}, argsStructPtr interface{}) MapArgsResultValuesFunc
type PrintlnText ¶
type PrintlnText string
PrintlnText prints a fixed string if a command returns without an error
func (PrintlnText) HandleResults ¶
type ResultsHandler ¶
type ResultsHandlerFunc ¶
var Println ResultsHandlerFunc = func(args Args, argVals, resultVals []reflect.Value, resultErr error) error { if resultErr != nil { return resultErr } results, err := resultsToInterfaces(resultVals) if err != nil || len(results) == 0 { return err } for _, r := range results { _, err = fmt.Println(r) if err != nil { return err } } return nil }
Println calls fmt.Println for every result
func LogTo ¶
func LogTo(logger Logger) ResultsHandlerFunc
LogTo calls logger.Printf(fmt.Sprintln(results...))
func LogWithPrefixTo ¶
func LogWithPrefixTo(prefix string, logger Logger) ResultsHandlerFunc
LogWithPrefixTo calls logger.Printf(fmt.Sprintln(results...)) with prefix prepended to the results
func PrintTo ¶
func PrintTo(writer io.Writer) ResultsHandlerFunc
PrintTo calls fmt.Fprint on writer with the result values as varidic arguments
func PrintlnTo ¶
func PrintlnTo(writer io.Writer) ResultsHandlerFunc
PrintlnTo calls fmt.Fprintln on writer for every result
func PrintlnWithPrefix ¶
func PrintlnWithPrefix(prefix string) ResultsHandlerFunc
PrintlnWithPrefix calls fmt.Println(prefix, result) for every result value
func PrintlnWithPrefixTo ¶
func PrintlnWithPrefixTo(prefix string, writer io.Writer) ResultsHandlerFunc
PrintlnWithPrefixTo calls fmt.Fprintln(writer, prefix, result) for every result value
func (ResultsHandlerFunc) HandleResults ¶
type StringArgsCommandLogger ¶
type StringArgsCommandLoggerFunc ¶
func (StringArgsCommandLoggerFunc) LogStringArgsCommand ¶
func (f StringArgsCommandLoggerFunc) LogStringArgsCommand(command string, args []string)
type StringArgsDispatcher ¶
type StringArgsDispatcher struct {
// contains filtered or unexported fields
}
func NewStringArgsDispatcher ¶
func NewStringArgsDispatcher(loggers ...StringArgsCommandLogger) *StringArgsDispatcher
func (*StringArgsDispatcher) AddCommand ¶
func (disp *StringArgsDispatcher) AddCommand(command, description string, commandFunc interface{}, args Args, resultsHandlers ...ResultsHandler) error
func (*StringArgsDispatcher) AddDefaultCommand ¶
func (disp *StringArgsDispatcher) AddDefaultCommand(description string, commandFunc interface{}, args Args, resultsHandlers ...ResultsHandler) error
func (*StringArgsDispatcher) DispatchCombinedCommandAndArgs ¶
func (*StringArgsDispatcher) DispatchDefaultCommand ¶
func (disp *StringArgsDispatcher) DispatchDefaultCommand() error
func (*StringArgsDispatcher) HasCommnd ¶
func (disp *StringArgsDispatcher) HasCommnd(command string) bool
func (*StringArgsDispatcher) HasDefaultCommnd ¶
func (disp *StringArgsDispatcher) HasDefaultCommnd() bool
func (*StringArgsDispatcher) MustAddCommand ¶
func (disp *StringArgsDispatcher) MustAddCommand(command, description string, commandFunc interface{}, args Args, resultsHandlers ...ResultsHandler)
func (*StringArgsDispatcher) MustAddDefaultCommand ¶
func (disp *StringArgsDispatcher) MustAddDefaultCommand(description string, commandFunc interface{}, args Args, resultsHandlers ...ResultsHandler)
func (*StringArgsDispatcher) MustDispatch ¶
func (disp *StringArgsDispatcher) MustDispatch(ctx context.Context, command string, args ...string)
func (*StringArgsDispatcher) MustDispatchCombinedCommandAndArgs ¶
func (disp *StringArgsDispatcher) MustDispatchCombinedCommandAndArgs(ctx context.Context, commandAndArgs []string) (command string)
func (*StringArgsDispatcher) MustDispatchDefaultCommand ¶
func (disp *StringArgsDispatcher) MustDispatchDefaultCommand()
func (*StringArgsDispatcher) PrintCommands ¶
func (disp *StringArgsDispatcher) PrintCommands(appName string)
func (*StringArgsDispatcher) PrintCommandsUsageIntro ¶
func (disp *StringArgsDispatcher) PrintCommandsUsageIntro(appName string, output io.Writer)
type StringArgsFunc ¶
func GetStringArgsFunc ¶
func GetStringArgsFunc(commandFunc interface{}, argsStructPtr interface{}, resultsHandlers ...ResultsHandler) (StringArgsFunc, error)
func MustGetStringArgsFunc ¶
func MustGetStringArgsFunc(commandFunc interface{}, argsStructPtr interface{}, resultsHandlers ...ResultsHandler) StringArgsFunc
type StringArgsResultValuesFunc ¶
func GetStringArgsResultValuesFunc ¶
func GetStringArgsResultValuesFunc(commandFunc interface{}, argsStructPtr interface{}) (StringArgsResultValuesFunc, error)
func MustGetStringArgsResultValuesFunc ¶
func MustGetStringArgsResultValuesFunc(commandFunc interface{}, argsStructPtr interface{}) StringArgsResultValuesFunc
type StringMapArgsFunc ¶
func GetStringMapArgsFunc ¶
func GetStringMapArgsFunc(commandFunc interface{}, argsStructPtr interface{}, resultsHandlers ...ResultsHandler) (StringMapArgsFunc, error)
func MustGetStringMapArgsFunc ¶
func MustGetStringMapArgsFunc(commandFunc interface{}, argsStructPtr interface{}, resultsHandlers ...ResultsHandler) StringMapArgsFunc
type StringMapArgsResultValuesFunc ¶
type StringMapArgsResultValuesFunc func(ctx context.Context, args map[string]string) ([]reflect.Value, error)
func GetStringMapArgsResultValuesFunc ¶
func GetStringMapArgsResultValuesFunc(commandFunc interface{}, argsStructPtr interface{}) (StringMapArgsResultValuesFunc, error)
func MustGetStringMapArgsResultValuesFunc ¶
func MustGetStringMapArgsResultValuesFunc(commandFunc interface{}, argsStructPtr interface{}) StringMapArgsResultValuesFunc
type SuperCommandNotFound ¶
type SuperCommandNotFound string
func (SuperCommandNotFound) Error ¶
func (s SuperCommandNotFound) Error() string
type SuperStringArgsDispatcher ¶
type SuperStringArgsDispatcher struct {
// contains filtered or unexported fields
}
func NewSuperStringArgsDispatcher ¶
func NewSuperStringArgsDispatcher(loggers ...StringArgsCommandLogger) *SuperStringArgsDispatcher
func (*SuperStringArgsDispatcher) AddDefaultCommand ¶
func (disp *SuperStringArgsDispatcher) AddDefaultCommand(description string, commandFunc interface{}, args Args, resultsHandlers ...ResultsHandler) error
func (*SuperStringArgsDispatcher) AddSuperCommand ¶
func (disp *SuperStringArgsDispatcher) AddSuperCommand(superCommand string) (subDisp *StringArgsDispatcher, err error)
func (*SuperStringArgsDispatcher) DispatchCombinedCommandAndArgs ¶
func (*SuperStringArgsDispatcher) DispatchDefaultCommand ¶
func (disp *SuperStringArgsDispatcher) DispatchDefaultCommand() error
func (*SuperStringArgsDispatcher) HasCommnd ¶
func (disp *SuperStringArgsDispatcher) HasCommnd(superCommand string) bool
func (*SuperStringArgsDispatcher) HasSubCommnd ¶
func (disp *SuperStringArgsDispatcher) HasSubCommnd(superCommand, command string) bool
func (*SuperStringArgsDispatcher) MustAddDefaultCommand ¶
func (disp *SuperStringArgsDispatcher) MustAddDefaultCommand(description string, commandFunc interface{}, args Args, resultsHandlers ...ResultsHandler)
func (*SuperStringArgsDispatcher) MustAddSuperCommand ¶
func (disp *SuperStringArgsDispatcher) MustAddSuperCommand(superCommand string) (subDisp *StringArgsDispatcher)
func (*SuperStringArgsDispatcher) MustDispatch ¶
func (disp *SuperStringArgsDispatcher) MustDispatch(ctx context.Context, superCommand, command string, args ...string)
func (*SuperStringArgsDispatcher) MustDispatchCombinedCommandAndArgs ¶
func (disp *SuperStringArgsDispatcher) MustDispatchCombinedCommandAndArgs(ctx context.Context, commandAndArgs []string) (superCommand, command string)
func (*SuperStringArgsDispatcher) MustDispatchDefaultCommand ¶
func (disp *SuperStringArgsDispatcher) MustDispatchDefaultCommand()
func (*SuperStringArgsDispatcher) PrintCommands ¶
func (disp *SuperStringArgsDispatcher) PrintCommands(appName string)
func (*SuperStringArgsDispatcher) PrintCommandsUsageIntro ¶
func (disp *SuperStringArgsDispatcher) PrintCommandsUsageIntro(appName string, output io.Writer)