Documentation ¶
Index ¶
- Constants
- Variables
- func CmdNameLT(i, j *Command) bool
- func RegisterSwitchHandlerMethods(s Switcher, handlersIter liter.Iter[*reflector.Method], log io.Writer) ([]reflect.Type, error)
- type Command
- type CommandDetails
- type CommandWriter
- type Commands
- type Handler
- type MethodsRegistrar
- type Switch
- type Switcher
Constants ¶
const ( ErrRegisterInterface = lerr.Str("handler argument to RegisterInterface requires a func or a channel") ErrNoHandler = lerr.Str("no handler found") )
Variables ¶
var DefaultRegistrar = MethodsRegistrar{ Handlers: filter.MethodName(filter.Suffix("Handler")), Detailer: func(m *reflector.Method) *CommandDetails { ln := len(m.Name) rs := []rune(m.Name[:ln-7]) um := m.On.MethodByName(string(rs) + "Usage") var out *CommandDetails if um.Kind() != reflect.Invalid && usageMethodType(um.Type()) { out = um.Call(nil)[0].Interface().(*CommandDetails) } else { out = &CommandDetails{} } rs[0] = unicode.ToLower(rs[0]) if out.Name == "" { out.Name = string(rs) } return out }, }
Functions ¶
Types ¶
type CommandDetails ¶
type CommandWriter ¶
type CommandWriter struct { Padding string Recursive bool // contains filtered or unexported fields }
make public add options (padding, newline, recursive) could this use navigator?
type Commands ¶
type Commands struct {
// contains filtered or unexported fields
}
func (*Commands) Seek ¶
Seek consumes 'path' until no command is found. The int indicates the number of strings used. This allows a full line of input to be passed into Seek and the remainder can be processed as arguments.
func (*Commands) Writer ¶
func (cs *Commands) Writer(path []string) *CommandWriter
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a func that takes 0 or 1 arguments, may have 1 return of any type and may have and error return argument. For example, if the return type is a string, the valid returns are (),(string),(error), (string, error). A Handler can also be identified by name.
func (*Handler) Handle ¶
Handle calls the underlying function with 'i' as the argument. If 'i' is not a valid argument Handle will panic.
func (*Handler) HandleValue ¶
HandleValue calls the underlying function with 'v' as the argument. If 'v' is not a valid argument HandleValue will panic.
type MethodsRegistrar ¶
type MethodsRegistrar struct { Handlers filter.Filter[*reflector.Method] Detailer func(*reflector.Method) *CommandDetails Log io.Writer }
func (MethodsRegistrar) HandlersFilter ¶
func (mr MethodsRegistrar) HandlersFilter() filter.Filter[*reflector.Method]
type Switch ¶
type Switch struct {
// contains filtered or unexported fields
}
Switch holds a set of Handlers and can invoke the correct handler by either name or type.
func (*Switch) Handle ¶
Handle will invoke a handler using 'i'. If 'i' is a string, it will try to match by name. Otherwise, it will try to match by type. This will result in unpredictable behavior if matching by name and type if one of the Handlers is a string handler.
func (*Switch) RegisterHandler ¶
func (*Switch) RegisterInterface ¶
RegisterInterface a handler with ListenerMux. It will return the argument type for the handler. The handler must be either a handler function or a receiver channel.