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 BaseCommand
- func (c *BaseCommand) Add(commands ...Command) Command
- func (c *BaseCommand) Children() []Command
- func (c *BaseCommand) EmbeddedCommand() *cobra.Command
- func (c *BaseCommand) Exec() error
- func (c *BaseCommand) Find(name string) (Command, error)
- func (c *BaseCommand) FullName() string
- func (c *BaseCommand) GetName() string
- func (c *BaseCommand) HasChild() bool
- func (c *BaseCommand) Parent() Command
- func (c *BaseCommand) Run(args []string) error
- func (c *BaseCommand) SetFullName(name string) Command
- func (c *BaseCommand) SetName(name string) Command
- func (c *BaseCommand) SetParent(p Command) Command
- type Command
- type CommandNameValue
- type TestApplication
Constants ¶
const (
// RootCommandName the instance name of cli.rootCommand
RootCommandName = "cli.rootCommand"
)
Variables ¶
ErrCommandHandlerNotFound the error message for 'command handler not found'
ErrCommandNotFound command not found error
Functions ¶
func Dispatch ¶ added in v0.9.0
Dispatch method with OnAction prefix
Types ¶
type Application ¶
type Application interface { app.Application Root() Command SetRoot(root Command) }
Application cli application interface
func NewApplication ¶
func NewApplication(cmd ...interface{}) Application
NewApplication create new cli application
type BaseCommand ¶
BaseCommand is the base command
func (*BaseCommand) Add ¶
func (c *BaseCommand) Add(commands ...Command) Command
Add added child command
func (*BaseCommand) EmbeddedCommand ¶
func (c *BaseCommand) EmbeddedCommand() *cobra.Command
EmbeddedCommand get embedded command
func (*BaseCommand) Find ¶
func (c *BaseCommand) Find(name string) (Command, error)
Find find child command
func (*BaseCommand) FullName ¶
func (c *BaseCommand) FullName() string
FullName get command full name
func (*BaseCommand) HasChild ¶
func (c *BaseCommand) HasChild() bool
HasChild check whether it has child or not
func (*BaseCommand) SetFullName ¶
func (c *BaseCommand) SetFullName(name string) Command
SetFullName set command full name
func (*BaseCommand) SetName ¶
func (c *BaseCommand) SetName(name string) Command
SetName set command name
func (*BaseCommand) SetParent ¶
func (c *BaseCommand) SetParent(p Command) Command
SetParent set parent command
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() *flag.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 TestApplication ¶
type TestApplication interface { Application RunTest(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