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 Debugf(format string, v ...interface{})
- func IsDebugMode() bool
- func IsGteVerbose(verb VerbLevel) bool
- func Logf(level VerbLevel, format string, v ...interface{})
- func NotExitOnEnd() func(*App)
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func ResetGOpts()
- func ResetVerbose()
- func SetCrazyMode()
- func SetDebugMode()
- func SetQuietMode()
- func SetStrictMode(strict bool)
- func SetVerbose(verbose VerbLevel)
- 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) AliasesMapping() map[string]string
- 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 (app *App) Config(fn func(a *App))
- 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 interface{}) bool
- func (b *App) GetCommand(name string) *Command
- func (c App) GlobalFlags() *Flags
- func (b *App) HasCommand(name string) bool
- func (b *App) HasCommands() bool
- func (app *App) HasSubcommands() bool
- func (b *App) IsAlias(alias string) bool
- func (b *App) IsCommand(name string) bool
- func (b *App) Match(names []string) *Command
- func (b *App) MatchByPath(path string) *Command
- func (app *App) On(name string, handler HookFunc)
- func (c App) RawOsArgs() []string
- func (b *App) ResolveAlias(alias string) string
- func (app *App) Run(args []string) (code int)
- func (app *App) RunCmd(name string, args []string) int
- func (app *App) RunLine(argsLine string) int
- func (app *App) SetDefaultCommand(name string)
- func (b *App) SetLogo(logo string, style ...string)
- type Argument
- func (a *Argument) Array() (ss []string)
- func (a *Argument) GetValue() interface{}
- func (a *Argument) HasValue() bool
- func (a *Argument) HelpName() string
- func (a *Argument) Index() int
- func (a *Argument) Init() *Argument
- func (a *Argument) Int(defVal ...int) int
- func (a *Argument) IsEmpty() bool
- func (a *Argument) SetArrayed() *Argument
- func (a *Argument) SetValue(val interface{}) error
- func (a *Argument) String(defVal ...string) string
- func (a *Argument) StringSplit(sep ...string) (ss []string)
- func (a *Argument) Strings() (ss []string)
- func (a *Argument) With(fn func(arg *Argument)) *Argument
- func (a *Argument) WithValidator(fn func(interface{}) (interface{}, error)) *Argument
- type Arguments
- func (ags *Arguments) AddArg(name, desc string, requiredAndArrayed ...bool) *Argument
- func (ags *Arguments) AddArgByRule(name, rule string) *Argument
- func (ags *Arguments) AddArgument(arg *Argument) *Argument
- func (ags *Arguments) Arg(name string) *Argument
- func (ags *Arguments) ArgByIndex(i int) *Argument
- func (ags *Arguments) Args() []*Argument
- func (ags *Arguments) BindArg(arg *Argument) *Argument
- func (ags *Arguments) HasArg(name string) bool
- func (ags *Arguments) HasArgs() bool
- func (ags *Arguments) HasArguments() bool
- func (ags *Arguments) ParseArgs(args []string) (err error)
- func (ags *Arguments) SetName(name string)
- func (ags *Arguments) SetValidateNum(validateNum bool)
- type Booleans
- type Command
- func (c *Command) Add(sub *Command, more ...*Command)
- func (c *Command) AddCommand(sub *Command)
- func (b *Command) AddError(err error)
- func (c *Command) AddSubs(sub *Command, more ...*Command)
- func (b *Command) AliasesMapping() map[string]string
- func (c *Command) AliasesString(sep ...string) string
- func (c *Command) App() *App
- func (c *Command) AttachTo(app *App)
- 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 (c *Command) Copy() *Command
- func (c *Command) Disable()
- func (c *Command) Errorf(format string, v ...interface{}) error
- func (b *Command) FindByPath(path string) *Command
- func (b *Command) FindCommand(path string) *Command
- func (c *Command) Fire(event string, data interface{}) (stop bool)
- func (c *Command) GFlags() *Flags
- func (b *Command) GetCommand(name string) *Command
- func (c Command) GlobalFlags() *Flags
- func (b *Command) HasCommand(name string) bool
- func (b *Command) HasCommands() 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) IsStandalone() bool
- func (c *Command) IsSubCommand(name string) bool
- 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 ...interface{}) 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 (c Command) RawOsArgs() []string
- func (b *Command) ResolveAlias(alias string) string
- func (c *Command) Root() *Command
- func (c *Command) Run(args []string) (err error)
- func (c *Command) Runnable() bool
- func (c *Command) SetFunc(fn RunnerFunc)
- func (b *Command) SetLogo(logo string, style ...string)
- func (c *Command) SetParent(parent *Command)
- func (c *Command) ShowHelp()
- func (c *Command) Sub(name string) *Command
- func (c *Command) SubCommand(name string) *Command
- func (c *Command) Visible() bool
- func (c *Command) WithFunc(fn RunnerFunc) *Command
- func (c *Command) WithHidden() *Command
- type Commander
- type EnumString
- type FlagMeta
- type Flags
- func (fs *Flags) Bool(name, shorts string, defValue bool, desc string) *bool
- func (fs *Flags) BoolOpt(p *bool, name, shorts string, defValue bool, desc string)
- func (fs *Flags) BoolVar(p *bool, meta *FlagMeta)
- func (fs *Flags) FSet() *flag.FlagSet
- func (fs *Flags) FSetArgs() []string
- func (fs *Flags) FlagMeta(name string) *FlagMeta
- func (fs *Flags) FlagNames() map[string]int
- func (fs *Flags) Float64Opt(p *float64, name, shorts string, defValue float64, desc string)
- func (fs *Flags) Float64Var(p *float64, meta *FlagMeta)
- func (fs *Flags) FromStruct(s interface{}) error
- func (fs *Flags) HasFlag(name string) bool
- func (fs *Flags) HasFlagMeta(name string) bool
- func (fs *Flags) HasOption(name string) bool
- func (fs *Flags) InitFlagSet(name string)
- func (fs *Flags) Int(name, shorts string, defValue int, desc string) *int
- func (fs *Flags) Int64(name, shorts string, defValue int64, desc string) *int64
- func (fs *Flags) Int64Opt(p *int64, name, shorts string, defValue int64, desc string)
- func (fs *Flags) Int64Var(p *int64, meta *FlagMeta)
- func (fs *Flags) IntOpt(p *int, name, shorts string, defValue int, desc string)
- func (fs *Flags) IntVar(p *int, meta *FlagMeta)
- func (fs *Flags) IsOption(name string) bool
- func (fs *Flags) IsShortName(short string) bool
- func (fs *Flags) IsShortOpt(short string) bool
- func (fs *Flags) IterAll(fn func(f *flag.Flag, meta *FlagMeta))
- func (fs *Flags) Len() int
- func (fs *Flags) LookupFlag(name string) *flag.Flag
- func (fs *Flags) Metas() map[string]*FlagMeta
- func (fs *Flags) Name() string
- func (fs *Flags) Parse(args []string) (err error)
- func (fs *Flags) PrintHelpPanel()
- func (fs *Flags) RawArg(i int) string
- func (fs *Flags) RawArgs() []string
- func (fs *Flags) Required(names ...string)
- func (fs *Flags) Run(args []string)
- func (fs *Flags) SetFlagSet(fSet *flag.FlagSet)
- func (fs *Flags) SetHelpRender(fn func())
- func (fs *Flags) SetOptions(opt *FlagsOption)
- func (fs *Flags) SetOutput(out io.Writer)
- func (fs *Flags) ShortNames(name string) (ss []string)
- func (fs *Flags) Str(name, shorts string, defValue, desc string) *string
- func (fs *Flags) StrOpt(p *string, name, shorts, defValue, desc string)
- func (fs *Flags) StrVar(p *string, meta *FlagMeta)
- func (fs *Flags) String() string
- func (fs *Flags) Uint(name, shorts string, defValue uint, desc string) *uint
- func (fs *Flags) Uint64(name, shorts string, defValue uint64, desc string) *uint64
- func (fs *Flags) Uint64Opt(p *uint64, name, shorts string, defValue uint64, desc string)
- func (fs *Flags) Uint64Var(p *uint64, meta *FlagMeta)
- func (fs *Flags) UintOpt(p *uint, name, shorts string, defValue uint, desc string)
- func (fs *Flags) UintVar(p *uint, meta *FlagMeta)
- func (fs *Flags) Var(p flag.Value, meta *FlagMeta)
- func (fs *Flags) VarOpt(p flag.Value, name, shorts, desc string)
- func (fs *Flags) WithOptions(fns func(opt *FlagsOption)) *Flags
- type FlagsOption
- type GOptions
- type Handler
- type HandlersChain
- type HelpVars
- type HookCtx
- func (md *HookCtx) ClearData()
- func (md *HookCtx) Data() map[string]interface{}
- func (md *HookCtx) IntValue(key string) int
- func (hc *HookCtx) Name() string
- func (md *HookCtx) SetData(data map[string]interface{})
- func (md *HookCtx) SetValue(key string, val interface{})
- func (md *HookCtx) StrValue(key string) string
- func (md *HookCtx) Value(key string) interface{}
- type HookFunc
- type Hooks
- type Ints
- type Logo
- type Runner
- type RunnerFunc
- type String
- type Strings
- type VerbLevel
Constants ¶
const ( // OK success exit code OK = 0 // ERR error exit code ERR = 2 // GOON prepare run successful, goon run command GOON = -1 // CommandSep char CommandSep = ":" // HelpCommand name HelpCommand = "help" )
const ( EvtAppInit = "app.init" EvtAppPrepareAfter = "app.prepare.after" EvtAppRunBefore = "app.run.before" EvtAppRunAfter = "app.run.after" EvtAppRunError = "app.run.error" EvtCmdInit = "cmd.init" // EvtCmdNotFound app or sub command not found EvtCmdNotFound = "cmd.not.found" // EvtAppCmdNotFound app command not found EvtAppCmdNotFound = "app.cmd.not.found" // EvtCmdSubNotFound sub command not found EvtCmdSubNotFound = "cmd.sub.not.found" EvtCmdOptParsed = "cmd.opts.parsed" // EvtCmdRunBefore cmd run EvtCmdRunBefore = "cmd.run.before" EvtCmdRunAfter = "cmd.run.after" EvtCmdRunError = "cmd.run.error" // EvtCmdExecBefore cmd exec EvtCmdExecBefore = "cmd.exec.before" EvtCmdExecAfter = "cmd.exec.after" EvtCmdExecError = "cmd.exec.error" EvtGOptionsParsed = "gcli.gopts.parsed" )
constants for hooks event, there are default allowed event names
const ( AlignLeft = strutil.PosRight AlignRight = strutil.PosLeft // TagRuleNamed struct tag use named k-v rule. // eg: `flag:"name=int0;shorts=i;required=true;desc=int option message"` TagRuleNamed = 0 // TagRuleSimple struct tag use simple rule. // format: "desc;required;default;shorts" // eg: `flag:"int option message;required;;i"` TagRuleSimple = 1 )
The options alignment type - Align right, padding left - Align left, padding right
const HelpVarFormat = "{$%s}"
HelpVarFormat allow var replace on render help info. Default support:
"{$binName}" "{$cmd}" "{$fullCmd}" "{$workDir}"
Variables ¶
var ( // CLI create an default instance CLI = newCmdLine() // DefaultVerb the default verbose level DefaultVerb = VerbError )
var AppHelpTemplate = `` /* 652-byte string literal not displayed */
AppHelpTemplate help template for app(all commands) TODO {{if .HasSubcommands }} {$binName} [global options...] <info>COMMAND</> [--options ...] <info>SUBCOMMAND</> [--options ...] [arguments ...] {{end}}
var CmdHelpTemplate = `` /* 1052-byte string literal not displayed */
CmdHelpTemplate help template for a command
var (
// FlagTagName default tag name on struct
FlagTagName = "flag"
)
Functions ¶
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
// ExitOnEnd call os.Exit on running end
ExitOnEnd bool
// ExitFunc default is os.Exit
ExitFunc func(int)
// 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[gcli.EvtInit] = func () {}
})
func (*App) AddAliases ¶
AddAliases add alias names for a command
func (*App) AddCommand ¶
AddCommand add a new command to the app
func (*App) AliasesMapping ¶
AliasesMapping get cmd aliases mapping
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) GetCommand ¶
GetCommand get an command by name
func (*App) MatchByPath ¶
MatchByPath command by path. eg. "top:sub" or "top sub"
func (*App) ResolveAlias ¶
ResolveAlias get real command name by alias
func (*App) Run ¶
Run running application
Usage:
// run with os.Args
app.Run(nil)
app.Run(os.Args[1:])
// custom args
app.Run([]string{"cmd", ...})
func (*App) RunCmd ¶ added in v3.0.1
RunCmd running an 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 an 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
type Argument ¶
type Argument struct {
// Name argument name. it's required
Name string
// Desc argument description message
Desc string
// Type name. eg: string, int, array
// Type string
// ShowName is a name for display help. default is equals to Name.
ShowName string
// Required arg is required
Required bool
// Arrayed if is array, can allow accept multi values, and must in last.
Arrayed bool
// value *goutil.Value TODO ...
// value store parsed argument data. (type: string, []string)
Value interface{}
// Handler custom argument value handler on call GetValue()
Handler func(val interface{}) interface{}
// Validator you can add an validator, will call it on binding argument value
Validator func(val interface{}) (interface{}, error)
// contains filtered or unexported fields
}
Argument a command argument definition
func NewArgument ¶
NewArgument quick create an new command argument
func (*Argument) GetValue ¶
func (a *Argument) GetValue() interface{}
GetValue get value by custom handler func
func (*Argument) SetArrayed ¶ added in v3.0.1
SetArrayed the argument
func (*Argument) StringSplit ¶
StringSplit quick split a string argument to string slice
func (*Argument) WithValidator ¶
WithValidator set an value validator of the argument
type Arguments ¶
type Arguments struct {
// contains filtered or unexported fields
}
Arguments definition
func (*Arguments) AddArg ¶
AddArg binding an named argument for the command. Notice:
- Required argument cannot be defined after optional argument
- Only one array parameter is allowed
- The (array) argument of multiple values can only be defined at the end
Usage:
cmd.AddArg("name", "description")
cmd.AddArg("name", "description", true) // required
cmd.AddArg("names", "description", true, true) // required and is array
func (*Arguments) AddArgByRule ¶ added in v3.0.1
AddArgByRule add an arg by simple string rule
func (*Arguments) AddArgument ¶
AddArgument binding an named argument for the command.
Notice:
- Required argument cannot be defined after optional argument
- Only one array parameter is allowed
- The (array) argument of multiple values can only be defined at the end
func (*Arguments) Arg ¶
Arg get arg by defined name.
Usage:
intVal := ags.Arg("name").Int()
strVal := ags.Arg("name").String()
arrVal := ags.Arg("names").Array()
func (*Arguments) ArgByIndex ¶
ArgByIndex get named arg by index
func (*Arguments) SetValidateNum ¶
SetValidateNum check
type Command ¶
type Command struct {
// Flags options for the command
Flags
// Arguments for the command
Arguments
// Name is the full command name.
Name string
// Desc is the command description message.
Desc string
// Aliases is the command name's alias names
Aliases []string
// Category for the command
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
// module is the name for grouped commands
// subName is the name for grouped commands
// eg: "sys:info" -> module: "sys", subName: "info"
// module, subName string
// Examples some usage example display
Examples string
// Func is the command handler func. Func Runner
Func RunnerFunc
// Help is the long help message text
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 an 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) AliasesMapping ¶
AliasesMapping get cmd aliases mapping
func (*Command) AliasesString ¶
AliasesString returns aliases string
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) 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 an command by name
func (Command) GlobalFlags ¶
func (c Command) GlobalFlags() *Flags
GlobalFlags get the app GlobalFlags
func (*Command) IsSubCommand ¶
IsSubCommand name check. alias of the HasCommand()
func (*Command) MatchByPath ¶
MatchByPath command by path. eg. "top:sub"
func (*Command) MustRun ¶
MustRun Alone the current command, will panic on error
Usage:
// run with os.Args
cmd.MustRun(nil)
cmd.MustRun(os.Args[1:])
// custom args
cmd.MustRun([]string{"-a", ...})
func (*Command) ParentName ¶
Module name of the grouped command
func (*Command) ResolveAlias ¶
ResolveAlias get real command name by 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) Runnable ¶
Runnable reports whether the command can be run; otherwise it is a documentation pseudo-command such as import path.
func (*Command) SetFunc ¶
func (c *Command) SetFunc(fn RunnerFunc)
SetFunc Settings command handler func
func (*Command) SubCommand ¶
SubCommand get sub command by name. eg "sub"
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 EnumString ¶
type EnumString struct {
// contains filtered or unexported fields
}
EnumString The string flag list, implemented flag.Value interface
func (*EnumString) Set ¶
func (s *EnumString) Set(value string) error
Set new value, will check value is right
func (*EnumString) SetEnum ¶ added in v3.0.1
func (s *EnumString) SetEnum(enum []string)
SetEnum values
type FlagMeta ¶
type FlagMeta struct {
// varPtr interface{}
// name and description
Name, Desc string
// Alias of the name. isn't shorts. eg: name='dry-run' alias='dr' TODO
Alias string
// default value for the flag option
DefVal interface{}
// short names. eg: ["o", "a"]
Shorts []string
// advanced settings
// hidden the option on help
Hidden bool
// the option is required
Required bool
// Validator support validate the option flag value
Validator func(val string) error
// contains filtered or unexported fields
}
FlagMeta for an flag(option/argument)
func (*FlagMeta) Shorts2String ¶
Shorts2String join shorts to an string
type Flags ¶
type Flags struct {
// Desc message
Desc string
// ExitFunc for handle exit
ExitFunc func(code int)
// contains filtered or unexported fields
}
Flags struct definition
func (*Flags) FSetArgs ¶
FSetArgs get all raw arguments. alias of the RawArgs() if have been called parse, the return is remaining args.
func (*Flags) Float64Opt ¶
Float64Opt binding an float64 option
func (*Flags) Float64Var ¶
Float64Var binding an float64 option flag
func (*Flags) FromStruct ¶
FromStruct from struct tag binding options
func (*Flags) HasFlagMeta ¶
HasFlagMeta check it is has FlagMeta
func (*Flags) InitFlagSet ¶
InitFlagSet create and init flag.FlagSet
func (*Flags) IsShortName ¶
IsShortcut check it is a shortcut name
func (*Flags) IsShortOpt ¶
IsShortOpt alias of the IsShortcut()
func (*Flags) LookupFlag ¶
LookupFlag get flag.Flag by name
func (*Flags) Parse ¶
Parse given arguments
Usage:
gf := gcli.NewFlags() gf.BoolOpt(&debug, "debug", "", defDebug, "open debug mode") gf.UintOpt(&port, "port", "p", 18081, "the http server port") err := gf.Parse(os.Args[1:])
func (*Flags) PrintHelpPanel ¶
func (fs *Flags) PrintHelpPanel()
PrintHelpPanel for all options to the gf.out
func (*Flags) RawArgs ¶
RawArgs get all raw arguments. if have been called parse, the return is remaining args.
func (*Flags) Run ¶
Run flags parse and handle help render Usage:
gf := gcli.NewFlags() ... gf.Run(os.Args)
func (*Flags) SetFlagSet ¶
SetFlagSet set the raw *flag.FlagSet
func (*Flags) SetHelpRender ¶
func (fs *Flags) SetHelpRender(fn func())
SetHelpRender set the raw *flag.FlagSet.Usage
func (*Flags) ShortNames ¶
ShortNames get all short-names of the option
func (*Flags) VarOpt ¶
VarOpt binding a custom var option Usage:
var names gcli.Strings cmd.VarOpt(&names, "tables", "t", "description ...")
func (*Flags) WithOptions ¶
func (fs *Flags) WithOptions(fns func(opt *FlagsOption)) *Flags
WithOptions for the object.
type FlagsOption ¶
type FlagsOption struct {
// WithoutType dont display flag data type on print help
WithoutType bool
// NameDescOL flag and desc at one line on print help
NameDescOL bool
// Alignment flag name align left or right. default is: right
Alignment uint8
// TagName on struct
TagName string
// TagRuleType for struct tag value. default is TagRuleNamed
TagRuleType uint8
}
FlagsOption for render help information
type GOptions ¶
type GOptions struct {
NoColor bool
// contains filtered or unexported fields
}
GOptions global flag options
func (*GOptions) SetStrictMode ¶
SetStrictMode option
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. ie. the last handler is the main own.
type HelpVars ¶
type HelpVars struct {
// varLeft, varRight string
// varFormat string
// Vars you can add some vars map for render help info
Vars map[string]string
}
HelpVars struct. provide string var function for render help template.
func (*HelpVars) ReplaceVars ¶
ReplaceVars replace vars in the input string.
type HookCtx ¶
HookCtx struct
func (*HookCtx) SetData ¶
func (md *HookCtx) SetData(data map[string]interface{})
SetData set all data
type HookFunc ¶
type HookFunc func(data ...interface{}) (stop bool)
HookFunc definition. func arguments:
in app, like: func(app *App, data ...interface{})
in cmd, like: func(cmd *Command, data ...interface{})
type HookFunc func(obj interface{}, data interface{}) return: - True go on handle. default is True - False stop goon handle.
type Hooks ¶
type Hooks struct {
// contains filtered or unexported fields
}
Hooks struct. hookManager
type RunnerFunc ¶
RunnerFunc definition
type String ¶ added in v3.0.1
type String string
String type, an special string
Usage:
// case 1:
var names gcli.String
c.VarOpt(&names, "names", "", "multi name by comma split")
--names "tom,john,joy"
names.Split(",") -> []string{"tom","john","joy"}
// case 2:
var ids gcli.String
c.VarOpt(&ids, "ids", "", "multi id by comma split")
--names "23,34,56"
names.Ints(",") -> []int{23,34,56}
Directories
¶
| Path | Synopsis |
|---|---|
|
cliapp
command
|
|
|
ggit
command
|
|
|
multilevel
command
|
|
|
serveman
command
|
|
|
simpleone
command
|
|
|
sflag
Package sflag is an simple cli flag parse tool
|
Package sflag is an simple cli flag parse tool |
|
Package interact collect some interactive methods for CLI
|
Package interact collect some interactive methods for CLI |
|
Package progress provide terminal progress bar display.
|
Package progress provide terminal progress bar display. |
|
Package show provides some formatter tools for display data.
|
Package show provides some formatter tools for display data. |














