cli

package
v0.0.0-...-418145e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RootCommandName the instance name of cli.rootCommand
	RootCommandName = "cli.rootCommand"
)

Variables

View Source
var ErrCommandHandlerNotFound = errors.New("command handler not found")

ErrCommandHandlerNotFound the error message for 'command handler not found'

View Source
var ErrCommandNotFound = errors.New("command not found")

ErrCommandNotFound command not found error

Functions

func Dispatch

func Dispatch(c Command, args []string) (retVal interface{}, err error)

Dispatch method with OnAction prefix

func Register

func Register(c Command)

Register register

Types

type Application

type Application interface {
	app.Application
}

func NewApplication

func NewApplication(cmd ...interface{}) 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{}
}

type Host

type Host struct {
	// contains filtered or unexported fields
}

func SetupHostEnvironment

func SetupHostEnvironment(companyName string, appName string, version string, opts ...Option) *Host

安装host环境

func (*Host) Build

func (h *Host) Build(cmd ...interface{}) *Host

func (*Host) Run

func (h *Host) Run() *Host

type Option

type Option func(*Host)

type RootCommand

type RootCommand struct {
	// contains filtered or unexported fields
}

RootCommand root command qualifier

func (*RootCommand) Add

func (c *RootCommand) Add(commands ...Command) Command

Add added child command

func (*RootCommand) Children

func (c *RootCommand) Children() []Command

Children get children

func (*RootCommand) EmbeddedCommand

func (c *RootCommand) EmbeddedCommand() *cobra.Command

EmbeddedCommand get embedded command

func (*RootCommand) Exec

func (c *RootCommand) Exec() error

Exec exec method

func (*RootCommand) Find

func (c *RootCommand) Find(name string) (Command, error)

Find find child command

func (*RootCommand) FullName

func (c *RootCommand) FullName() string

FullName get command full name

func (*RootCommand) GetName

func (c *RootCommand) GetName() string

GetName get command name

func (*RootCommand) HasChild

func (c *RootCommand) HasChild() bool

HasChild check whether it has child or not

func (*RootCommand) Parent

func (c *RootCommand) Parent() Command

Parent get parent command

func (*RootCommand) Run

func (c *RootCommand) Run(args []string) error

Run method

func (*RootCommand) SetFullName

func (c *RootCommand) SetFullName(name string) Command

SetFullName set command full name

func (*RootCommand) SetName

func (c *RootCommand) SetName(name string) Command

SetName set command name

func (*RootCommand) SetParent

func (c *RootCommand) SetParent(p Command) Command

SetParent set parent command

type SubCommand

type SubCommand struct {
	// contains filtered or unexported fields
}

SubCommand sub command qualifier

func (*SubCommand) Add

func (c *SubCommand) Add(commands ...Command) Command

Add added child command

func (*SubCommand) Children

func (c *SubCommand) Children() []Command

Children get children

func (*SubCommand) EmbeddedCommand

func (c *SubCommand) EmbeddedCommand() *cobra.Command

EmbeddedCommand get embedded command

func (*SubCommand) Exec

func (c *SubCommand) Exec() error

Exec exec method

func (*SubCommand) Find

func (c *SubCommand) Find(name string) (Command, error)

Find find child command

func (*SubCommand) FullName

func (c *SubCommand) FullName() string

FullName get command full name

func (*SubCommand) GetName

func (c *SubCommand) GetName() string

GetName get command name

func (*SubCommand) HasChild

func (c *SubCommand) HasChild() bool

HasChild check whether it has child or not

func (*SubCommand) Parent

func (c *SubCommand) Parent() Command

Parent get parent command

func (*SubCommand) Run

func (c *SubCommand) Run(args []string) error

Run method

func (*SubCommand) SetFullName

func (c *SubCommand) SetFullName(name string) Command

SetFullName set command full name

func (*SubCommand) SetName

func (c *SubCommand) SetName(name string) Command

SetName set command name

func (*SubCommand) SetParent

func (c *SubCommand) SetParent(p Command) Command

SetParent set parent command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL