Documentation
¶
Overview ¶
Package gcli is a simple-to-use command line application and tool library.
Contains: cli app, flags parse, interact, progress, data show tools.
Source code and other details for the project are available at GitHub:
https://github.com/gookit/gcli
Usage please refer examples and see README
Index ¶
- Constants
- Variables
- func CommitID() string
- func Config(fn func(opts *GlobalOpts))
- func Debugf(format string, v ...any)
- func EnhanceShort() uint8
- func IsDebugMode() bool
- func IsGteVerbose(verb VerbLevel) bool
- func Logf(level VerbLevel, format string, v ...any)
- func NewFlags(nameWithDesc ...string) *gflag.Flags
- func NotExitOnEnd() func(*App)
- func Print(args ...any)
- func Printf(format string, args ...any)
- func Println(args ...any)
- func ResetGOpts()
- func ResetVerbose()
- func SetDebugMode()
- func SetEnhanceShort(level uint8)
- func SetQuietMode()
- func SetStrictMode(strict bool)
- func SetVerbose[T VerbLevel | string](verbose T)
- func StrictMode() bool
- func Version() string
- type App
- func (app *App) Add(c *Command, more ...*Command)
- func (app *App) AddAliases(name string, aliases ...string)
- func (app *App) AddCommand(c *Command)
- func (b *App) AddError(err error)
- func (app *App) AddHandler(h Handler)
- func (b *App) AddHelpVar(key string, val any)
- func (b *App) AliasesMapping() map[string]string
- func (app *App) AppOpts() *AppOptions
- func (b *App) BinDir() string
- func (b *App) BinName() string
- func (b *App) ChWorkDir(dir string) error
- func (b *App) CmdAliases() *structs.Aliases
- func (b *App) CmdNameMap() map[string]int
- func (b *App) CmdNames() []string
- func (b *App) Command(name string) (c *Command, exist bool)
- func (app *App) CommandName() string
- func (b *App) CommandNames() []string
- func (b *App) Commands() map[string]*Command
- func (b *App) CommandsByGroup(defaultTitle string) []*CmdGroup
- func (app *App) Config(fns ...func(a *App))
- func (b *App) Errors() error
- func (app *App) Exec(path string, args []string) error
- func (app *App) Exit(code int)
- func (b *App) FindByPath(path string) *Command
- func (b *App) FindCommand(path string) *Command
- func (app *App) Fire(event string, data map[string]any) bool
- func (app *App) Flags() *Flags
- func (app *App) GenCompletionHelp(binName ...string) string
- func (app *App) GenCompletionScript(shell string, binName ...string) (string, error)
- func (app *App) GenStaticCompletionScript(shell string, binName ...string) (string, error)
- func (b *App) GetCommand(name string) *Command
- func (b *App) HasCommand(name string) bool
- func (b *App) HasCommands() bool
- func (b *App) HasSubcommands() bool
- func (b *App) IsAlias(alias string) bool
- func (b *App) IsCommand(name string) bool
- func (b *App) LastError() error
- func (b *App) Match(names []string) *Command
- func (b *App) MatchByPath(path string) *Command
- func (app *App) On(name string, handler HookFunc)
- func (app *App) Opts() *GlobalOpts
- func (app *App) QuickRun() int
- func (b *App) ResetData()
- func (b *App) ResolveAlias(alias string) string
- func (b *App) ResolveCommand(name string) (c *Command, exist bool)
- func (app *App) Run(args []string) (code int)
- func (app *App) RunArgs(args ...string) int
- func (app *App) RunCmd(name string, args []string) error
- func (app *App) RunLine(argsLine string) int
- func (app *App) SetDefaultCommand(name string)
- func (b *App) SetLogo(logo string, style ...string)
- func (app *App) Use(handlers ...RunnerFunc) *App
- func (b *App) WorkDir() string
- type AppOptions
- type Argument
- type Arguments
- type Booleans
- type CliArg
- type CliArgs
- type CliOpt
- type CmdGroup
- type Command
- func (c *Command) Add(sub *Command, more ...*Command)
- func (c *Command) AddCommand(sub *Command)
- func (b *Command) AddError(err error)
- func (b *Command) AddHelpVar(key string, val any)
- func (c *Command) AddSubs(sub *Command, more ...*Command)
- func (b *Command) AliasesMapping() map[string]string
- func (c *Command) App() *App
- func (c *Command) AttachTo(app *App)
- func (b *Command) BinDir() string
- func (b *Command) BinName() string
- func (b *Command) ChWorkDir(dir string) error
- func (b *Command) CmdAliases() *structs.Aliases
- func (b *Command) CmdNameMap() map[string]int
- func (b *Command) CmdNames() []string
- func (b *Command) Command(name string) (c *Command, exist bool)
- func (b *Command) CommandNames() []string
- func (b *Command) Commands() map[string]*Command
- func (b *Command) CommandsByGroup(defaultTitle string) []*CmdGroup
- func (c *Command) Copy() *Command
- func (c *Command) Disable()
- func (b *Command) Errors() error
- func (b *Command) FindByPath(path string) *Command
- func (b *Command) FindCommand(path string) *Command
- func (c *Command) Fire(event string, data map[string]any) (stop bool)
- func (b *Command) GetCommand(name string) *Command
- func (b *Command) HasCommand(name string) bool
- func (b *Command) HasCommands() bool
- func (b *Command) HasSubcommands() bool
- func (c *Command) HelpDesc() (desc string)
- func (c *Command) ID() string
- func (c *Command) Init()
- func (b *Command) IsAlias(alias string) bool
- func (b *Command) IsCommand(name string) bool
- func (c *Command) IsDisabled() bool
- func (c *Command) IsRoot() bool
- func (c *Command) IsRunnable() bool
- func (c *Command) IsStandalone() bool
- func (c *Command) IsSubCommand(name string) bool
- func (b *Command) LastError() error
- func (c *Command) Match(names []string) *Command
- func (c *Command) MatchByPath(path string) *Command
- func (c *Command) MustRun(args []string)
- func (c *Command) NewErr(msg string) error
- func (c *Command) NewErrf(format string, v ...any) error
- func (c *Command) Next()
- func (c *Command) NotStandalone() bool
- func (c *Command) On(name string, handler HookFunc)
- func (c *Command) Parent() *Command
- func (c *Command) ParentName() string
- func (c *Command) Path() string
- func (c *Command) PathNames() []string
- func (b *Command) ResetData()
- func (b *Command) ResolveAlias(alias string) string
- func (b *Command) ResolveCommand(name string) (c *Command, exist bool)
- func (c *Command) Root() *Command
- func (c *Command) Run(args []string) (err error)
- func (c *Command) SetFunc(fn RunnerFunc)
- func (b *Command) SetLogo(logo string, style ...string)
- func (c *Command) SetParent(parent *Command)
- func (c *Command) SharedOpts() *gflag.Flags
- func (c *Command) ShowHelp() (err error)
- func (c *Command) Sub(name string) *Command
- func (c *Command) SubCommand(name string) *Command
- func (c *Command) Use(handlers ...RunnerFunc) *Command
- func (c *Command) Visible() bool
- func (c *Command) WithFunc(fn RunnerFunc) *Command
- func (c *Command) WithHidden() *Command
- func (b *Command) WorkDir() string
- type Context
- func (ctx *Context) ArgLine() string
- func (ctx *Context) BinDir() string
- func (ctx *Context) BinFile() string
- func (ctx *Context) BinName() string
- func (ctx *Context) InitCtx() *Context
- func (ctx *Context) OsArgs() []string
- func (ctx *Context) OsName() string
- func (ctx *Context) PID() int
- func (ctx *Context) PIDString() string
- func (ctx *Context) ResetData()
- func (ctx *Context) UpWorkDir(dir string)
- func (ctx *Context) Value(key any) any
- func (ctx *Context) WorkDir() string
- type EnumString
- type FlagMeta
- type Flags
- type FlagsConfig
- type FoundState
- type GlobalOpts
- type Handler
- type HandlersChain
- type HelpConfig
- type HelpReplacer
- type HookCtx
- type HookFunc
- type Hooks
- type Ints
- type Logo
- type PrepareState
- type Runner
- type RunnerFunc
- type String
- type Strings
- type VerbLevel
Constants ¶
const ( ZshShell = "zsh" BashShell = "bash" PwshShell = "pwsh" // PowerShell )
current supported shell for completion script generate
const ( // EvtAppInitBefore on app init before EvtAppInitBefore = gevent.OnAppInitBefore // EvtAppInit on app init after EvtAppInit = gevent.OnAppInitAfter // EvtAppExit on app exit EvtAppExit = gevent.OnAppExit // EvtAppBindOptsBefore before bind app options EvtAppBindOptsBefore = gevent.OnAppBindOptsBefore // EvtAppBindOptsAfter after bind app options EvtAppBindOptsAfter = gevent.OnAppBindOptsAfter // EvtAppCmdAdd on app cmd add before EvtAppCmdAdd = gevent.OnAppCmdAdd // EvtAppCmdAdded on app cmd added EvtAppCmdAdded = gevent.OnAppCmdAdded // EvtAppOptsParsed on app options parsed EvtAppOptsParsed = gevent.OnAppOptsParsed // EvtAppHelpBefore before render app help EvtAppHelpBefore = gevent.OnAppHelpBefore // EvtAppHelpAfter after render app help EvtAppHelpAfter = gevent.OnAppHelpAfter // EvtAppPrepareAfter prepare for run, after the EvtAppOptsParsed EvtAppPrepareAfter = gevent.OnAppPrepared EvtAppRunBefore = gevent.OnAppRunBefore EvtAppRunAfter = gevent.OnAppRunAfter EvtAppRunError = gevent.OnAppRunError // EvtCmdInitBefore on cmd init before EvtCmdInitBefore = gevent.OnCmdInitBefore // EvtCmdInit on cmd init after EvtCmdInit = gevent.OnCmdInitAfter // EvtCmdNotFound app or sub command not found EvtCmdNotFound = gevent.OnCmdNotFound // EvtAppCmdNotFound app command not found EvtAppCmdNotFound = gevent.OnAppCmdNotFound // EvtCmdSubNotFound sub command not found EvtCmdSubNotFound = gevent.OnCmdSubNotFound EvtCmdOptParsed = gevent.OnCmdOptParsed // EvtCmdRunBefore cmd run EvtCmdRunBefore = gevent.OnCmdRunBefore EvtCmdRunAfter = gevent.OnCmdRunAfter EvtCmdRunError = gevent.OnCmdRunError // EvtCmdExecBefore cmd exec EvtCmdExecBefore = gevent.OnCmdExecBefore EvtCmdExecAfter = gevent.OnCmdExecAfter EvtCmdExecError = gevent.OnCmdExecError EvtGOptionsParsed = gevent.OnGlobalOptsParsed )
constants for hooks event, there are default allowed event names.
These are aliases for the gevent.* event names. So user code can reference them directly from gcli without importing the gevent package.
const ( // CommandSep char CommandSep = ":" // HelpCommand name HelpCommand = "help" // VerbEnvName for set gcli debug level VerbEnvName = "GCLI_VERBOSE" )
const ( // TagRuleNamed struct tag use named k-v rule. eg: `flag:"name=int0;shorts=i;required=true;desc=message"` TagRuleNamed = gflag.TagRuleNamed // TagRuleSimple struct tag use simple rule. eg: `flag:"name;desc;required;default;shorts"` TagRuleSimple = gflag.TagRuleSimple // TagRuleField struct tag use field name as option name, read meta from independent tag keys. // eg: `flag:"shorts" desc:"message" default:"val" required:"true"` TagRuleField = gflag.TagRuleField )
TagRule* alias of the gflag struct-tag rule type consts. see Flags.FromStruct
const ( // EnhanceShortNone do not enhance short option parse. (default) EnhanceShortNone = gflag.EnhanceShortNone // EnhanceShortMerge merge bool short option group. eg: `-aux` = `-a -u -x` EnhanceShortMerge = gflag.EnhanceShortMerge // EnhanceShortAttach also support value-attached short. eg: `-Ostdout` = `-O stdout` EnhanceShortAttach = gflag.EnhanceShortAttach )
EnhanceShort* alias of the gflag short-option enhance level consts. see Flags Config.EnhanceShort
const HelpVarFormat = "{$%s}"
HelpVarFormat allow string replace on render help info.
Default support:
"{$binName}" "{$cmd}" "{$fullCmd}" "{$workDir}"
const InheritedOptsCategory = "Inherited Options"
InheritedOptsCategory 是继承(共享)选项在命令 help 中的分组标题。
Variables ¶
var AppHelpTemplate = `` /* 715-byte string literal not displayed */
AppHelpTemplate help template for app(all commands)
var CmdHelpTemplate = `` /* 993-byte string literal not displayed */
CmdHelpTemplate help template for a command
Functions ¶
func EnhanceShort ¶ added in v3.5.0
func EnhanceShort() uint8
EnhanceShort get the global POSIX short-option enhance level.
func SetEnhanceShort ¶ added in v3.5.0
func SetEnhanceShort(level uint8)
SetEnhanceShort set the global POSIX short-option enhance level for all commands.
level: EnhanceShortNone(0) / EnhanceShortMerge(1) / EnhanceShortAttach(2).
NOTE: a command's own Config.EnhanceShort (if set non-zero) takes priority over this.
func SetVerbose ¶
SetVerbose level by name or level
Types ¶
type App ¶
type App struct {
// Name app name
Name string
// Desc app description
Desc string
// Func on run app, if is empty will display help.
Func func(app *App, args []string) error
// contains filtered or unexported fields
}
App the cli app definition
func NewApp ¶
NewApp create new app instance.
Usage:
NewApp()
// Or with a config func
NewApp(func(a *App) {
// do something before init ....
a.Hooks[gevent.OnAppInitAfter] = func () {}
})
func (*App) AddAliases ¶
AddAliases add alias names for a command
func (*App) AddCommand ¶
AddCommand add a new command to the app
func (*App) AddHelpVar ¶ added in v3.1.1
AddHelpVar to instance.
func (*App) AliasesMapping ¶
AliasesMapping get cmd aliases mapping
func (*App) AppOpts ¶ added in v3.8.0
func (app *App) AppOpts() *AppOptions
AppOpts get the app's own parse/run state (help/version/completion).
func (*App) CommandsByGroup ¶ added in v3.4.0
CommandsByGroup group all visible commands by their Category field.
- groups keep the category insertion order(see base.cmdCategories). - the default group(empty Category) uses defaultTitle as its title. - returns nil when there is no visible command.
func (*App) Errors ¶ added in v3.8.2
func (b *App) Errors() error
Errors fetch, will clear after fetch.
func (*App) Exec ¶
Exec direct exec other command in current command
Name can be:
- top command name in the app. 'top'
- command path in the app. 'top sub'
Usage:
app.Exec("top")
app.Exec("top:sub")
app.Exec("top sub")
app.Exec("top sub", []string{"-a", "val0", "arg0"})
func (*App) FindByPath ¶
FindByPath command by path. eg: "top:sub" or "top sub"
func (*App) FindCommand ¶
FindCommand command by path. eg: "top:sub" or "top sub"
func (*App) Flags ¶ added in v3.1.0
Flags get. TIP: you can custom binding applicaton options
Usage:
app.Flags().BoolOpt(...) app.Flags().StrOpt(...)
func (*App) GenCompletionHelp ¶ added in v3.6.0
GenCompletionHelp 生成 --gen-completion 的使用与 shell profile 配置说明。
func (*App) GenCompletionScript ¶ added in v3.4.1
GenCompletionScript 生成指定 shell 的**动态(瘦)**补全脚本文本(默认方式)。
瘦脚本不硬编码命令/选项, 而是回调 `bin --in-completion <已输入词...>` 动态取候选, 命令/选项变化后无需重新生成脚本, 零维护。
- shell: 目标 shell, 取值 bash|zsh, 其它返回 error。
- binName: 可选, 覆盖脚本中使用的 bin 名(如 genac 的 --bin-name); 不传则使用当前应用的 bin 名。
func (*App) GenStaticCompletionScript ¶ added in v3.4.1
GenStaticCompletionScript 生成指定 shell 的**静态(嵌入式)**补全脚本文本。
静态脚本把当前已注册的命令名/描述/选项硬编码进脚本; 命令/选项变化后需重新生成。 一般推荐使用 GenCompletionScript(瘦/动态); 仅在无法回调二进制等场景下用此 opt-in 方式。
- shell: 目标 shell, 取值 bash|zsh, 其它返回 error。
- binName: 可选, 覆盖脚本中使用的 bin 名(如 genac 的 --bin-name); 不传则使用当前应用的 bin 名。
生成所需的数据(BinName、命令名/描述、各命令选项等)均从 app 当前已注册的命令中取得。
func (*App) GetCommand ¶
GetCommand get a direct children command by name, not support alias.
func (*App) HasCommand ¶
HasCommand top command name check
func (*App) LastError ¶ added in v3.8.2
func (b *App) LastError() error
LastError fetch, will clear after fetch.
func (*App) MatchByPath ¶
MatchByPath command by path. eg: "top:sub" or "top sub"
func (*App) Opts ¶ added in v3.1.0
func (app *App) Opts() *GlobalOpts
Opts get the process-level GlobalOpts (verbose/strict/enhanceShort, shared). for the app's own parse state (help/version/completion) use AppOpts().
func (*App) ResolveAlias ¶
ResolveAlias get real command name by alias
func (*App) ResolveCommand ¶ added in v3.8.1
ResolveCommand gets a direct children command by name or alias.
func (*App) Run ¶
Run the application with input args
Usage:
// run with os.Args
app.Run(nil)
app.Run(os.Args[1:])
// custom args
app.Run([]string{"cmd", "--name", "inhere"})
func (*App) RunCmd ¶ added in v3.0.1
RunCmd running a top command with custom args
Usage:
app.Exec("top")
app.Exec("top", []string{"-a", "val0", "arg0"})
// can add sub command on args
app.Exec("top", []string{"sub", "-o", "abc"})
func (*App) RunLine ¶
RunLine manual run a command by command line string.
eg: app.RunLine("top --top-opt val0 sub --sub-opt val1 arg0")
func (*App) SetDefaultCommand ¶
SetDefaultCommand set default command name
func (*App) Use ¶ added in v3.4.1
func (app *App) Use(handlers ...RunnerFunc) *App
Use 注册应用级中间件, 对所有命令在其自身中间件与主函数之前执行; 返回 app 以便链式调用。
type AppOptions ¶ added in v3.8.0
type AppOptions struct {
// ShowHelp show help information, then exit.
ShowHelp bool
// ShowVersion show version information, then exit.
ShowVersion bool
// contains filtered or unexported fields
}
AppOptions per-app(or standalone command) parse & run state. Each App owns its own instance, so concurrent App instances in one process don't share these.
type Argument ¶
Argument alias of the gflag.CliArg
func NewArgument ¶
NewArgument quick create a new command argument
type CmdGroup ¶ added in v3.4.0
type CmdGroup struct {
// Name is the category name. "" means the default group.
Name string
// Title is the display title for help. eg: "Available Commands"
Title string
// Cmds are the visible commands of this group, sorted by name.
Cmds []*Command
}
CmdGroup is a group of commands by category. used for render help.
type Command ¶
type Command struct {
// Flags cli (options+arguments) parse and manage for the command
gflag.Flags
// Name is the command name.
Name string
// Desc is the command description message.
// Can use string-var in contents, eg: {$cmd}
Desc string
// Aliases is the command name's alias names
Aliases arrutil.Strings
// Category for grouped command display on help
Category string
// Config func, will call on `initialize`.
//
// - you can config options and other init works
Config func(c *Command)
// Hidden the command on render help
Hidden bool
// Subs sub commands of the Command
// NOTICE: if command has been initialized, adding through this field is invalid
Subs []*Command
// Func is the command handler func. Func Runner
//
// TIP:
// params: `args` is the remain arguments after parse flags(options and arguments).
Func RunnerFunc
// Examples some usage example display.
//
// Can use string-var in contents, eg:
// {$cmd}, {$binName}, {$binDir}, {$workDir}, {$binWithCmd}, {$binWithPath}, {$fullCmd}
Examples string
// Help is the long help message text
//
// Can use string-var in contents, eg:
// {$cmd}, {$binName}, {$binDir}, {$workDir}, {$binWithCmd}, {$binWithPath}, {$fullCmd}
Help string
// HelpRender custom render cmd help message
HelpRender func(c *Command)
// contains filtered or unexported fields
}
Command a CLI command structure
func NewCommand ¶
NewCommand create a new command instance.
Usage:
cmd := NewCommand("my-cmd", "description")
// OR with a config func
cmd := NewCommand("my-cmd", "description", func(c *Command) { ... })
app.Add(cmd) // OR cmd.AttachTo(app)
func (*Command) AddCommand ¶
AddCommand add a sub command
func (*Command) AddHelpVar ¶ added in v3.1.1
AddHelpVar to instance.
func (*Command) AliasesMapping ¶
AliasesMapping get cmd aliases mapping
func (*Command) BinDir ¶ added in v3.1.1
func (b *Command) BinDir() string
BinDir get bin script dirname
func (*Command) BinName ¶ added in v3.1.1
func (b *Command) BinName() string
BinName get bin script name
func (*Command) CmdAliases ¶
CmdAliases get cmd aliases
func (*Command) CmdNameMap ¶
CmdNameMap get all command names
func (*Command) CommandNames ¶
func (b *Command) CommandNames() []string
CommandNames get all command names
func (*Command) CommandsByGroup ¶ added in v3.4.0
CommandsByGroup group all visible commands by their Category field.
- groups keep the category insertion order(see base.cmdCategories). - the default group(empty Category) uses defaultTitle as its title. - returns nil when there is no visible command.
func (*Command) Errors ¶ added in v3.8.2
func (b *Command) Errors() error
Errors fetch, will clear after fetch.
func (*Command) FindByPath ¶
FindByPath command by path. eg: "top:sub" or "top sub"
func (*Command) FindCommand ¶
FindCommand command by path. eg: "top:sub" or "top sub"
func (*Command) GetCommand ¶
GetCommand get a direct children command by name, not support alias.
func (*Command) HasCommand ¶
HasCommand top command name check
func (*Command) HasSubcommands ¶ added in v3.1.0
func (b *Command) HasSubcommands() bool
HasSubcommands on the app
func (*Command) IsRunnable ¶ added in v3.1.1
IsRunnable reports whether the command can be run; otherwise it is a documentation pseudo-command such as import path.
func (*Command) IsSubCommand ¶
IsSubCommand name check. alias of the HasCommand()
func (*Command) LastError ¶ added in v3.8.2
func (b *Command) LastError() error
LastError fetch, will clear after fetch.
func (*Command) MatchByPath ¶
MatchByPath command by path. eg: "top:sub"
func (*Command) MustRun ¶
MustRun Alone the current command, will output message on error
Usage:
// run with os.Args
cmd.MustRun(nil)
cmd.MustRun(os.Args[1:])
// custom args
cmd.MustRun([]string{"-a", ...})
func (*Command) ParentName ¶
ParentName name of the parent command
func (*Command) ResolveAlias ¶
ResolveAlias get real command name by alias
func (*Command) ResolveCommand ¶ added in v3.8.1
ResolveCommand gets a direct children command by name or alias.
func (*Command) Run ¶
Run standalone running the command
Usage:
// run with os.Args
cmd.Run(nil)
cmd.Run(os.Args[1:])
// custom args
cmd.Run([]string{"-a", ...})
func (*Command) SetFunc ¶
func (c *Command) SetFunc(fn RunnerFunc)
SetFunc Settings command handler func
func (*Command) SharedOpts ¶ added in v3.8.0
SharedOpts 返回命令专属的共享选项持有器(惰性创建), 对标 cobra 的 PersistentFlags()。
在它上面像普通选项一样绑定(BoolOpt/StrOpt/Opt[T]/FromStruct/...), 这些选项会被本命令 及其所有子孙命令继承: 父命令定义、子命令也能解析, 且父子读写同一个变量(共享 flag.Value)。
注意: sharedFs 仅作为「定义来源」, 自身永不单独 Parse; 分发时由 parseOptions 合并进 c.Flags。
func (*Command) SubCommand ¶
SubCommand get sub command by name. eg "sub"
func (*Command) Use ¶ added in v3.4.1
func (c *Command) Use(handlers ...RunnerFunc) *Command
Use 注册一个或多个中间件, 按注册顺序在命令主函数前依次执行; 返回 c 以便链式调用。
func (*Command) WithFunc ¶
func (c *Command) WithFunc(fn RunnerFunc) *Command
WithFunc Settings command handler func
func (*Command) WithHidden ¶ added in v3.0.1
WithHidden Settings command is hidden
type Context ¶ added in v3.1.0
Context struct
type EnumString ¶
type EnumString = cflag.EnumString
EnumString The string flag list, implemented flag.Value interface
type FlagsConfig ¶ added in v3.0.3
FlagsConfig alias of the gflag.Config
type FoundState ¶ added in v3.3.0
type FoundState int8
FoundState for match command name. 0=not found, 1=found
const ( // NotFound not found command by input NotFound FoundState = iota Founded )
type GlobalOpts ¶ added in v3.1.0
type GlobalOpts struct {
// Disable auto binding global options
Disable bool
NoColor bool
// set the message report level.
//
// can set by env: GCLI_VERBOSE=debug. see VerbEnvName
Verbose VerbLevel
// NoProgress dont display progress. env: NO_PROGRESS
NoProgress bool
// NoInteractive close interactive confirm. env: NO_INTERACTIVE
NoInteractive bool
// contains filtered or unexported fields
}
GlobalOpts process-level config options. shared across all App instances via the package singleton gOpts; set by gcli.SetVerbose / SetStrictMode / SetEnhanceShort.
NOTE: per-app parse/run state (help/version/completion) lives in AppOptions, so multiple App instances in one process don't share it. see App.AppOpts().
func (*GlobalOpts) SetDisable ¶ added in v3.1.0
func (g *GlobalOpts) SetDisable()
SetDisable global options
func (*GlobalOpts) SetEnhanceShort ¶ added in v3.5.0
func (g *GlobalOpts) SetEnhanceShort(level uint8)
SetEnhanceShort global level. see EnhanceShortNone/Merge/Attach
func (*GlobalOpts) SetStrictMode ¶ added in v3.1.0
func (g *GlobalOpts) SetStrictMode(strictMode bool)
SetStrictMode option
func (*GlobalOpts) SetVerbose ¶ added in v3.1.0
func (g *GlobalOpts) SetVerbose(verbose VerbLevel)
SetVerbose value
type Handler ¶
type Handler interface {
// Creator for create new command
Creator() *Command
// Config bind Flags or Arguments for the command
Config(c *Command)
// Execute the command
Execute(c *Command, args []string) error
}
Handler interface definition
type HandlersChain ¶
type HandlersChain []RunnerFunc
HandlersChain middleware handlers chain definition
func (HandlersChain) Last ¶
func (c HandlersChain) Last() RunnerFunc
Last returns the last handler in the chain. tip: the last handler is the main own.
type HelpConfig ¶ added in v3.3.0
type HelpConfig struct {
// AfterCmdText add text after commands list
AfterCmdText string
FooterText string
}
HelpConfig struct
type HelpReplacer ¶ added in v3.1.1
type HelpReplacer struct {
VarOpen, VarClose string
// contains filtered or unexported fields
}
HelpReplacer provide string var replace for render help template.
func (*HelpReplacer) AddReplace ¶ added in v3.1.1
func (hv *HelpReplacer) AddReplace(name, value string)
AddReplace get command name. AddReplace
func (*HelpReplacer) AddReplaces ¶ added in v3.1.1
func (hv *HelpReplacer) AddReplaces(vars map[string]string)
AddReplaces add multi tpl vars.
func (*HelpReplacer) GetReplace ¶ added in v3.1.1
func (hv *HelpReplacer) GetReplace(name string) string
GetReplace get a help var by name
func (*HelpReplacer) ReplacePairs ¶ added in v3.1.1
func (hv *HelpReplacer) ReplacePairs(input string) string
ReplacePairs replace string vars in the input text.
func (*HelpReplacer) Replaces ¶ added in v3.1.1
func (hv *HelpReplacer) Replaces() map[string]string
Replaces get all tpl vars.
type HookCtx ¶
type HookCtx struct {
context.Context
maputil.Data
App *App
Cmd *Command
// contains filtered or unexported fields
}
HookCtx struct
type HookFunc ¶
HookFunc definition.
Returns:
- True for stop continue run.
- False continue handle next logic.
type Hooks ¶
type Hooks struct {
// contains filtered or unexported fields
}
Hooks struct. hookManager
type PrepareState ¶ added in v3.3.0
type PrepareState int8
PrepareState value. 0=ok, 2=error, -1=goon
const ( // OK success exit code. eg: help command, fired event OK PrepareState = 0 // ERR error exit code ERR PrepareState = 2 // GOON prepare run successful, goon run command GOON PrepareState = -1 )
type Runner ¶
type Runner interface {
// Run the command
//
// TIP:
// args is the remain arguments after parse flags(options and arguments).
Run(c *Command, remainArgs []string) error
}
Runner /Executor interface
type RunnerFunc ¶
RunnerFunc definition
TIP:
args is the remain arguments after parse flags(options and arguments).
type VerbLevel ¶
type VerbLevel uint
VerbLevel type.
const ( VerbQuiet VerbLevel = iota // don't report anything VerbError // reporting on error, default level. VerbWarn VerbInfo VerbDebug VerbCrazy )
constants for error level (quiet 0 - 5 crazy)
func VerbLevelFrom ¶ added in v3.3.0
VerbLevelFrom level name string.
Directories
¶
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
bannerdemo
command
|
|
|
cliapp
command
|
|
|
emojitest
command
|
|
|
ggit
command
|
|
|
issues
command
|
|
|
multilevel
command
|
|
|
rawflag
command
|
|
|
serveman
command
|
|
|
sflag
Package sflag is an simple cli flag parse tool
|
Package sflag is an simple cli flag parse tool |
|
simpleone
command
|
|
|
testterm
command
|
|
|
Package docgen 提供把 gcli 命令/应用导出为 markdown 与 man page(roff) 文档的能力。
|
Package docgen 提供把 gcli 命令/应用导出为 markdown 与 man page(roff) 文档的能力。 |
|
Package gflag provide command line options and arguments binding, parse, management.
|
Package gflag provide command line options and arguments binding, parse, management. |
|
internal
|
|





