Documentation
¶
Overview ¶
Package cli provides quick start framework for command line application.
The main features of Hiboot cli application are ¶
* Dependency Injection * Struct Tag for dependency injection * Sub command handler
Index ¶
- Constants
- Variables
- func Dispatch(c Command, args []string) (retVal interface{}, err error)
- func Register(c Command)
- type Application
- type Command
- type CommandNameValue
- type RootCommand
- func (c *RootCommand) Add(commands ...Command) Command
- func (c *RootCommand) Children() []Command
- func (c *RootCommand) EmbeddedCommand() *cobra.Command
- func (c *RootCommand) Exec() error
- func (c *RootCommand) Find(name string) (Command, error)
- func (c *RootCommand) FullName() string
- func (c *RootCommand) GetName() string
- func (c *RootCommand) HasChild() bool
- func (c *RootCommand) Parent() Command
- func (c *RootCommand) Run(args []string) error
- func (c *RootCommand) SetFullName(name string) Command
- func (c *RootCommand) SetName(name string) Command
- func (c *RootCommand) SetParent(p Command) Command
- type SubCommand
- func (c *SubCommand) Add(commands ...Command) Command
- func (c *SubCommand) Children() []Command
- func (c *SubCommand) EmbeddedCommand() *cobra.Command
- func (c *SubCommand) Exec() error
- func (c *SubCommand) Find(name string) (Command, error)
- func (c *SubCommand) FullName() string
- func (c *SubCommand) GetName() string
- func (c *SubCommand) HasChild() bool
- func (c *SubCommand) Parent() Command
- func (c *SubCommand) Run(args []string) error
- func (c *SubCommand) SetFullName(name string) Command
- func (c *SubCommand) SetName(name string) Command
- func (c *SubCommand) SetParent(p Command) Command
- type TestApplication
Constants ¶
const (
// RootCommandName the instance name of cli.rootCommand
RootCommandName = "cli.rootCommand"
)
Variables ¶
var ErrCommandHandlerNotFound = errors.New("command handler not found")
ErrCommandHandlerNotFound the error message for 'command handler not found'
var ErrCommandNotFound = errors.New("command not found")
ErrCommandNotFound command not found error
Functions ¶
Types ¶
type Application ¶
type Application interface {
app.Application
}
Application cli application interface
func NewApplication ¶
func NewApplication(cmd ...interface{}) Application
NewApplication create new cli application
type Command ¶
type Command interface {
// EmbeddedCommand return the embedded command
EmbeddedCommand() *cobra.Command
// Add add a new command
Add(commands ...Command) Command
// HasChild check if it has child
HasChild() bool
// Children get children
Children() []Command
// Exec execute the command
Exec() error
// GetName get the command name
GetName() string
// FullName get the command full name
FullName() string
// SetName set the command name
SetName(name string) Command
// SetFullName set the command full name
SetFullName(name string) Command
// Parent get parent command
Parent() Command
// SetParent set parent command
SetParent(p Command) Command
// Run the callback of command, once the command is received, this method will be called
Run(args []string) error
// Find find child command
Find(name string) (Command, error)
// SetOutput set output, type: io.Writer
SetOutput(output io.Writer)
// SetArgs set args
SetArgs(a []string)
// ExecuteC execute command
ExecuteC() (cmd *cobra.Command, err error)
// PersistentFlags get persistent flags
PersistentFlags() *pflag.FlagSet
}
Command the command interface for cli application
type CommandNameValue ¶
type CommandNameValue struct {
Name string
Command interface{}
}
CommandNameValue is the command name value pair
type RootCommand ¶ added in v0.9.6
type RootCommand struct {
at.Qualifier `value:"cli.rootCommand"`
// contains filtered or unexported fields
}
RootCommand root command qualifier
func (*RootCommand) Children ¶ added in v0.9.6
func (c *RootCommand) Children() []Command
Children get children
func (*RootCommand) EmbeddedCommand ¶ added in v0.9.6
EmbeddedCommand get embedded command
func (*RootCommand) FullName ¶ added in v0.9.6
func (c *RootCommand) FullName() string
FullName get command full name
func (*RootCommand) GetName ¶ added in v0.9.6
func (c *RootCommand) GetName() string
GetName get command name
func (*RootCommand) HasChild ¶ added in v0.9.6
func (c *RootCommand) HasChild() bool
HasChild check whether it has child or not
func (*RootCommand) Parent ¶ added in v0.9.6
func (c *RootCommand) Parent() Command
Parent get parent command
func (*RootCommand) SetFullName ¶ added in v0.9.6
SetFullName set command full name
type SubCommand ¶ added in v0.9.6
type SubCommand struct {
// contains filtered or unexported fields
}
SubCommand sub command qualifier
func (*SubCommand) Children ¶ added in v0.9.6
func (c *SubCommand) Children() []Command
Children get children
func (*SubCommand) EmbeddedCommand ¶ added in v0.9.6
EmbeddedCommand get embedded command
func (*SubCommand) FullName ¶ added in v0.9.6
func (c *SubCommand) FullName() string
FullName get command full name
func (*SubCommand) GetName ¶ added in v0.9.6
func (c *SubCommand) GetName() string
GetName get command name
func (*SubCommand) HasChild ¶ added in v0.9.6
func (c *SubCommand) HasChild() bool
HasChild check whether it has child or not
func (*SubCommand) Parent ¶ added in v0.9.6
func (c *SubCommand) Parent() Command
Parent get parent command
func (*SubCommand) SetFullName ¶ added in v0.9.6
SetFullName set command full name
type TestApplication ¶
type TestApplication interface {
Initialize() error
SetProperty(name string, value ...interface{}) TestApplication
Run(args ...string) (output string, err error)
}
TestApplication the interface of cli test application
func NewTestApplication ¶
func NewTestApplication(t *testing.T, cmd ...interface{}) TestApplication
NewTestApplication is the test application constructor