Documentation ¶
Overview ¶
GO-COP is a utility to add functions easy to use from the tty. Autocomplete sugestions is context aware, and the command structure is quite liberal, meening that multiple optional or greedy arguments are allowed, though not encurraged.
Index ¶
- Variables
- type AcInvoker
- type AcInvokerFn
- type AcSugestor
- type AcSugestorFn
- type ArgNode
- func (an *ArgNode) AddArgument(name string) *ArgNode
- func (an *ArgNode) AddCustomNode(name string, acsFn AcSugestorFn, aciFn AcInvokerFn, apFn acceptPermutationsFn, ...) *ArgNode
- func (an *ArgNode) AddSubCommand(name string) *ArgNode
- func (an *ArgNode) Description(str string) *ArgNode
- func (an *ArgNode) Handler(rhf RunHandlerFunc) *ArgNode
- func (an *ArgNode) InvokeCommand(input string, rc RunContext) (res interface{}, err error)
- func (an *ArgNode) Optional() *ArgNode
- func (an *ArgNode) SugestAutoComplete(in TokenSet) []string
- func (an *ArgNode) Times(min, max uint64) *ArgNode
- func (an *ArgNode) Usage(prfix, descpr string) (ret []string)
- func (an *ArgNode) Weight(ts TokenSet) int
- type CommandParser
- type DefaultRunContext
- type InvalidArgument
- type NodeTypeFlags
- type ResultHandlerFn
- type RunContext
- type RunContextProviderFn
- type RunHandler
- type RunHandlerFunc
- type SugestionProvider
- type Token
- type TokenSet
- type TokenType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AcInvoker ¶
type AcInvoker interface {
Invoke(assignment *argNodeAssignment, context RunContext)
}
Interface for invoking a command, and populate the arguments
type AcInvokerFn ¶
type AcInvokerFn func(assignment *argNodeAssignment, context RunContext)
A function that registers and applies the value on resultMap
func (AcInvokerFn) Invoke ¶
func (aif AcInvokerFn) Invoke(assignment *argNodeAssignment, context RunContext)
Implement AcInvoker interface
type AcSugestor ¶
Interface for autocomplete sugestions
type AcSugestorFn ¶
Autocomplete sugestion. Returns a slice of possible sugestions
type ArgNode ¶
type ArgNode struct { Name string Descr string Children []*ArgNode TypeFlags NodeTypeFlags AcSugestorFn AcInvokerFn RunHandler // contains filtered or unexported fields }
func NewWorldNode ¶
func NewWorldNode() *ArgNode
func (*ArgNode) AddArgument ¶
func (*ArgNode) AddCustomNode ¶
func (an *ArgNode) AddCustomNode(name string, acsFn AcSugestorFn, aciFn AcInvokerFn, apFn acceptPermutationsFn, typeFlags NodeTypeFlags) *ArgNode
func (*ArgNode) AddSubCommand ¶
func (*ArgNode) Description ¶
func (*ArgNode) Handler ¶
func (an *ArgNode) Handler(rhf RunHandlerFunc) *ArgNode
func (*ArgNode) InvokeCommand ¶
func (an *ArgNode) InvokeCommand(input string, rc RunContext) (res interface{}, err error)
func (*ArgNode) SugestAutoComplete ¶
type CommandParser ¶
type CommandParser struct { SugestionProvider SugestionProvider ResultHandler ResultHandlerFn // contains filtered or unexported fields }
func NewCommandParser ¶
func NewCommandParser() *CommandParser
func (*CommandParser) AddStandardCommands ¶
func (cp *CommandParser) AddStandardCommands(an *ArgNode)
func (*CommandParser) AutoCompleter ¶
func (cp *CommandParser) AutoCompleter(line string) (c []string)
func (*CommandParser) MainLoop ¶
func (cp *CommandParser) MainLoop() (err error)
func (*CommandParser) NewRunContext ¶
func (cp *CommandParser) NewRunContext() RunContext
func (*CommandParser) NewWorld ¶
func (cp *CommandParser) NewWorld() *ArgNode
Example ¶
package main import ( "log" "testing" ) var _ testing.T func main() { cp := NewCommandParser() // New world. IE, root node world := cp.NewWorld() // Add command1 with mandatory argument world.AddSubCommand("command1").AddArgument("argument") // Add command2 with optional argument world.AddSubCommand("command2").AddArgument("argument").Optional() // Print usage for _, u := range world.Usage("\t", "\t\t") { log.Print(u) } }
Output:
type DefaultRunContext ¶
type DefaultRunContext struct {
// contains filtered or unexported fields
}
func (*DefaultRunContext) Get ¶
func (drc *DefaultRunContext) Get(name string) string
func (*DefaultRunContext) Handler ¶
func (drc *DefaultRunContext) Handler(h RunHandler)
func (*DefaultRunContext) Invoke ¶
func (drc *DefaultRunContext) Invoke() (interface{}, error)
func (*DefaultRunContext) Put ¶
func (drc *DefaultRunContext) Put(name, value string)
func (*DefaultRunContext) SugestionProvider ¶
func (drc *DefaultRunContext) SugestionProvider() SugestionProvider
type InvalidArgument ¶
type InvalidArgument struct {
// contains filtered or unexported fields
}
func (*InvalidArgument) Error ¶
func (ia *InvalidArgument) Error() string
type NodeTypeFlags ¶
type NodeTypeFlags uint64
const ( WorldNode NodeTypeFlags = 1 << iota CommandNode ArgumentNode OptionalNode MultiArgNode )
type ResultHandlerFn ¶
type ResultHandlerFn func(interface{}, error)
type RunContext ¶
type RunContext interface { Put(name, value string) Get(name string) string SugestionProvider() SugestionProvider Handler(rh RunHandler) Invoke() (interface{}, error) }
func DefaultRunContextProvider ¶
func DefaultRunContextProvider(cp *CommandParser) RunContext
type RunContextProviderFn ¶
type RunContextProviderFn func(cp *CommandParser) RunContext
type RunHandler ¶
type RunHandler interface {
HandleCommand(rc RunContext) (interface{}, error)
}
type RunHandlerFunc ¶
type RunHandlerFunc func(rc RunContext) (interface{}, error)
func (RunHandlerFunc) HandleCommand ¶
func (rh RunHandlerFunc) HandleCommand(rc RunContext) (interface{}, error)
type SugestionProvider ¶
type SugestionProvider struct { }
type Token ¶
type Token struct { Type TokenType // Type // contains filtered or unexported fields }
Scanned token
func (*Token) IsWhitespace ¶
type TokenSet ¶
type TokenSet []Token
func (TokenSet) Filter ¶
Example ¶
tokens := Tokenize("\"A \"'input' string") log.Print("Initial tokens: ", tokens) log.Print("Filtered on not whitespace: ", tokens.Filter(TokenNoWhitespace)) log.Print("Filtered on single or double quoted string: ", tokens.Filter(TokenSQuoted|TokenDQuoted))
Output:
func (TokenSet) StartsWithIgnoreCase ¶
type TokenType ¶
type TokenType uint64
const ( TokenError TokenType = 1 << iota TokenEOF TokenString TokenDQuoted TokenSQuoted TokenWhitespace TokenNoWhitespace = TokenString | TokenDQuoted | TokenSQuoted TokenAllWhitespace = TokenEOF | TokenWhitespace )
Click to show internal directories.
Click to hide internal directories.