Documentation
¶
Index ¶
- Constants
- func DefaultCommandPath(path string)
- func DefaultDelimiter(delimiter string)
- func Execute(mountFuncs ...func(*cobra.Command))
- func GetCommand(verb string, delimiter string) *cobra.Command
- func MountCmd(verb string, cmd *Command, dictkey string) *cobra.Command
- func MountServer(rootCmd *cobra.Command)
- func RootLong(long string)
- func RootShort(short string)
- func RootVerb(verb string)
- type Cli
- type Command
- type Flag
Constants ¶
const ( // define valid flag type in command file. FLAG_TYPE_INT = "int" FLAG_TYPE_FLOAT = "float" FLAG_TYPE_STRING = "string" FLAG_TYPE_BOOL = "bool" )
Variables ¶
This section is empty.
Functions ¶
func DefaultCommandPath ¶
func DefaultCommandPath(path string)
DefaultCommandPath set default command path
func DefaultDelimiter ¶
func DefaultDelimiter(delimiter string)
func Execute ¶
Instruction execution entry. mountFunc represents that the root command is passed into this method, which is used to expand the mounting custom command set. There are some default internal mount method, like [mountVersion] etc. Perhaps we could obtain the context here to control which commands can be added to the command tree, but the simplest way is not to set a default command to add, ensuring that the command tree is always empty. This may be useful for some commands. Therefore, we can only add commands that are not related to business logic to the command tree as tools, and the commands related to writing later can be set in the actual project.
func GetCommand ¶
GetCommand return the cobra's Command from command dict and will panic if not exists the specific verb. It will set internal command dict cache in package cli.
func MountCmd ¶
MountCmd performs the same operation as the built-in mountCmd, except that it mounts the commands to the specified dictionary. If the specified dictionary does not exist, a panic is triggered.
func MountServer ¶
MountServer mount the verb-server to the instruction tree. For details, see the command.json file in the project structure to find the composition structure of the corresponding instruction.
Types ¶
type Cli ¶
type Cli struct {
App string `json:"app"` // cli name used for root command
Entry []string `json:"entry"` // execute entry, like Package main.
Version string `json:"version"` // cli version
Intro string `json:"intro"` // cli introduction
Commands []Command `json:"commands"` // all cli commands
}
Cli is the standard format after parsing the command file.
type Command ¶
type Command struct {
Verb string `json:"verb"` // called verb
ShortDesc string `json:"shortDesc"` // short description for verb
LongDesc string `json:"longDesc"` // long description for verb
PersistentFlags []Flag `json:"persistentFlags"` // persistent flags for current command
LocalFlags []Flag `json:"localFlags"` // local flags for current command
SubCommand []Command `json:"subCommands"` // subcommands for current command
}
Command store command information.
type Flag ¶
type Flag struct {
FullName string `json:"fullName"` // full name
ShortName string `json:"shortName"` // short name
Type string `json:"type"` // value type
Desc string `json:"desc"` // description
Default string `json:"default"` // default value
}
Flag store flag information.
func ParseLocalFlags ¶
ParseLocalFlags return the list for local flag of specific verb. No panic here.
func ParsePersistenFlags ¶
The idea here is to try to enter from any top-level instruction in the already successfully parsed CLI structure, but obviously this can be automatically obtained during the recursion process, so it is retained here, but there is a fast flag loading version. ParsePersistenFlags return the list for persistent flag of specific verb. No panic here.