Documentation
¶
Index ¶
- Variables
- func CreateEmptyArrayOfType(arrType ArgType) any
- func Reflect(namespace Namespace, obj any) error
- type ArgType
- type Argument
- type Command
- func (cmd *Command) CompressTokens(tokens []any) ([]any, error)
- func (cmd *Command) DisplayHelp()
- func (cmd *Command) Execute(tokens []any, processor *Processor, fromShell bool) error
- func (cmd *Command) Fullname() string
- func (cmd *Command) OnComplete(tokens []any, processor *Processor) []*ns.AutoComplete
- func (cmd *Command) Prepare() error
- func (cmd *Command) Process(cliArgs []string) error
- type CompletionFunc
- type Namespace
- type Option
- func (opt *Option) Apply(inp *OptionInput, namespace Namespace) error
- func (opt *Option) ApplyArrayDefaults(namespace Namespace)
- func (opt *Option) ApplyDefault(namespace Namespace)
- func (opt *Option) ArgTypeDisplay() string
- func (opt *Option) DefaultValueDisplay() string
- func (opt *Option) InvocationDisplay() string
- func (opt *Option) Validate() error
- type OptionInput
- type Processor
- func (p *Processor) AddCommand(cmd *Command) error
- func (p *Processor) AddCommands(cmds ...*Command) error
- func (p *Processor) OnComplete(beforeAndCursor string, afterCursor string, full string) []*ns.AutoComplete
- func (p *Processor) OnExecute(nilShell *ns.NilShell, input string)
- func (p *Processor) Process(cliArgs []string) error
- func (p *Processor) RemoveBuiltins(removeHelp bool)
- func (p *Processor) Shell() *ns.NilShell
Constants ¶
This section is empty.
Variables ¶
var Debug bool = false
Functions ¶
func CreateEmptyArrayOfType ¶ added in v0.2.0
Types ¶
type Argument ¶
type Argument struct {
Name string
Description string
Type ArgType // String is the default argument type
Default any // Default value (only valid in the final argument position)
MemberOf []string // When value must be a member of a limited collection (strings only)
CompletionFunc CompletionFunc // Used to dynamically list member values, with a prefix for optimization
IsArray bool // When true, argument becomes an array (must be in the final argument position)
}
func (*Argument) Apply ¶
Apply will apply the input to the target. If input is nil then the default will be applied
func (*Argument) ApplyArrayDefaults ¶ added in v0.2.2
ApplyArrayDefaults applies array defaults to the target if empty after processing
func (*Argument) ApplyDefault ¶
ApplyDefault applies the default value to the target
type Command ¶
type Command struct {
Name string
Group string // If specified, group will be presented in the help and similar items will be displayed together
Description string
SubCommands []*Command
// Commands which have subcommands cannot have any of the following
Options []*Option
Arguments []*Argument
OnExecute func(Namespace, *Processor) error
OnCompleteOverride func(cmd *Command, tokens []any, processor *Processor) []*ns.AutoComplete
// contains filtered or unexported fields
}
func (*Command) CompressTokens ¶
CompressTokens compresses any token/value pairs where required into a single *Option.
func (*Command) DisplayHelp ¶
func (cmd *Command) DisplayHelp()
DisplayHelp displays contextual help for the command
func (*Command) Execute ¶
Execute attempts to execute the supplied argument tokens after evaluating the input against the specified rules.
func (*Command) OnComplete ¶
func (cmd *Command) OnComplete(tokens []any, processor *Processor) []*ns.AutoComplete
type CompletionFunc ¶
type Option ¶
type Option struct {
ShortName byte
Name string
Description string
Type ArgType
Value any // When value is specified, the option has an implicit value and cannot be provided with --opt=value
Default any
IsArray bool // When true, argument can be reused multiple times
IsRequired bool // When true a value is required to be set
}
func (*Option) Apply ¶
func (opt *Option) Apply(inp *OptionInput, namespace Namespace) error
Apply will apply the input to the namespace. If input is nil then the default will be applied
func (*Option) ApplyArrayDefaults ¶ added in v0.2.0
ApplyArrayDefaults applies array defaults to the target if empty after processing
func (*Option) ApplyDefault ¶
ApplyDefault applies the default value to the target
func (*Option) ArgTypeDisplay ¶
ArgTypeDisplay returns the argument data type for display
func (*Option) DefaultValueDisplay ¶
DefaultValueDisplay returns the default value for display purposes
func (*Option) InvocationDisplay ¶
InvocationDisplay returns the help name for the option
type OptionInput ¶
type Processor ¶
type Processor struct {
DefaultHeading string
DisableBuiltins bool
// contains filtered or unexported fields
}
func NewProcessor ¶
func NewProcessor() *Processor
func (*Processor) AddCommand ¶
AddCommand adds a command to the processor. If the command is in some way invalid, an error will be returned here.
func (*Processor) AddCommands ¶ added in v0.1.6
AddCommands adds several commands to the processor at once
func (*Processor) OnComplete ¶
func (*Processor) Process ¶
Process processes the supplied cliArgs as though this were a standalone commmand. This is useful for processing arguments directly from the cli
func (*Processor) RemoveBuiltins ¶ added in v0.1.4
RemoveBuiltins removes all builtin commands including the help command if specified