Documentation ¶
Index ¶
- Variables
- type Argument
- type Command
- func (o *Command) Add(options ...*Option)
- func (o *Command) GetDescription() string
- func (o *Command) GetName() string
- func (o *Command) GetOption(key string) (opt *Option, has bool)
- func (o *Command) GetOptions() map[string]*Option
- func (o *Command) SetDescription(description string) *Command
- func (o *Command) SetProvider(provider Provider) *Command
- type CommandConfig
- type Configuration
- type Container
- func (o *Container) Add(commands ...*Command)
- func (o *Container) Context() context.Context
- func (o *Container) Del(commands ...*Command)
- func (o *Container) DelByName(name string)
- func (o *Container) GetArgument() *Argument
- func (o *Container) GetCommand(name string) (cmd *Command, has bool)
- func (o *Container) GetCommands() map[string]*Command
- func (o *Container) GetOutput() *Output
- func (o *Container) Run()
- func (o *Container) RunWith(args []string)
- type Help
- type Kind
- type Option
- func (o *Option) Generate() string
- func (o *Option) GetDefaultValue() any
- func (o *Option) GetDescription() string
- func (o *Option) GetKind() Kind
- func (o *Option) GetName() string
- func (o *Option) GetRequired() bool
- func (o *Option) GetShortName() string
- func (o *Option) GetSpecified() bool
- func (o *Option) SetDefaultValue(dv any) *Option
- func (o *Option) SetDescription(description string) *Option
- func (o *Option) SetKind(kind Kind) *Option
- func (o *Option) SetRequired(required bool) *Option
- func (o *Option) SetShortName(c byte) *Option
- func (o *Option) ToBool() bool
- func (o *Option) ToFloat() float64
- func (o *Option) ToInt() int64
- func (o *Option) ToString() string
- type Output
- type Provider
- type ProviderAfter
- type ProviderBefore
Constants ¶
This section is empty.
Variables ¶
var ( RegexArgumentMatchCommand = regexp.MustCompile(`^[a-zA-Z][-_a-zA-Z0-9:.]*$`) RegexArgumentMatchOption = regexp.MustCompile(`^-`) RegexArgumentMatchOptionWithFull = regexp.MustCompile(`^(-+)([a-zA-Z0-9][-_a-zA-Z0-9.]*)=(.+)`) RegexArgumentMatchOptionWithName = regexp.MustCompile(`^(-+)([a-zA-Z0-9][-_a-zA-Z0-9.]*)$`) )
Functions ¶
This section is empty.
Types ¶
type Argument ¶
type Argument struct {
// contains filtered or unexported fields
}
Argument is a component used to parse command-line arguments.
func (*Argument) GetCommandName ¶
GetCommandName returns a command name that defined in argument.
Usage:
go run main.go example
Output:
example
func (*Argument) GetOption ¶
GetOption returns an option value with given name if exists.
Usage:
go run main.go example --key=value
Code:
key, has := console.GetOption("key")
Output:
"value", true
func (*Argument) GetScriptExecutor ¶
func (*Argument) GetScriptPath ¶
GetScriptPath returns a real script path that called in argument.
Usage: (compiled)
/data/sketch/app example
Output:
/data/sketch/app
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command is a component used to schedule in container.
func (*Command) GetDescription ¶
GetDescription returns a command description.
func (*Command) GetName ¶
GetName returns a command name.
Code:
println(cmd.GetName())
Output:
example
func (*Command) GetOption ¶
GetOption returns an option in command if exists.
Code:
opt, has := cmd.GetOption("key")
Output:
&Option{}, true
func (*Command) SetDescription ¶
SetDescription set description for command.
func (*Command) SetProvider ¶
SetProvider set command provider. Method's in provider will be called when scheduler fired.
type CommandConfig ¶
CommandConfig is a component used to define options.
func (*CommandConfig) After ¶
func (o *CommandConfig) After() error
After is an event handler that called by parent.
func (*CommandConfig) GetOption ¶
func (o *CommandConfig) GetOption(name string) any
GetOption returns an option definition if defined in config file.
func (*CommandConfig) GetOptions ¶
func (o *CommandConfig) GetOptions() map[string]string
GetOptions returns an option mapper of a command.
type Configuration ¶
type Configuration struct { Commands map[string]*CommandConfig `yaml:"commands" json:"commands"` // contains filtered or unexported fields }
Configuration is a component used to configure console variables.
var Config *Configuration
Config is a singleton instance for console configuration.
func (*Configuration) After ¶
func (o *Configuration) After() (err error)
After is an event handler used to be called in config-file manager.
func (*Configuration) GetCommand ¶
func (o *Configuration) GetCommand(name string) *CommandConfig
GetCommand returns a command configuration if define in config file.
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is a component used to manage all components for console.
func NewContainer ¶
func NewContainer() *Container
NewContainer returns a singleton instance of package.
func (*Container) GetArgument ¶
GetArgument returns the singleton instance of Argument.
func (*Container) GetCommand ¶
GetCommand returns the singleton instance of Command if exists.
func (*Container) GetCommands ¶
GetCommands returns a commands mapper in container.
type Help ¶
type Help struct {
// contains filtered or unexported fields
}
Help is a built-in command provider used to print usages about console and command.
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option is an interface used to store command options.
func NewBoolOption ¶
func NewFloatOption ¶
func NewIntOption ¶
func NewNullOption ¶
func (*Option) GetDefaultValue ¶
func (*Option) GetDescription ¶
func (*Option) GetRequired ¶
func (*Option) GetShortName ¶
func (*Option) GetSpecified ¶
func (*Option) SetDefaultValue ¶
func (*Option) SetDescription ¶
func (*Option) SetRequired ¶
func (*Option) SetShortName ¶
type Output ¶
type Output struct{}
Output is a component used to send message to terminal.
type Provider ¶
Provider is a required handler. It's called when command scheduled and Before returned nil.