Documentation ¶
Index ¶
- Constants
- Variables
- func AddOnAfterXrefBuilt(cb HookXrefFunc)
- func AddOnBeforeXrefBuilding(cb HookXrefFunc)
- func AddOnConfigLoadedListener(c ConfigReloaded)
- func AsJSON() (b []byte)
- func AsToml() (b []byte)
- func AsYaml() (b []byte)
- func Clone(fromValue, toValue interface{}) interface{}
- func DumpAsString() (str string)
- func EnsureDir(dir string) (err error)
- func Exec(rootCmd *RootCommand) (err error)
- func ExecWith(rootCmd *RootCommand, beforeXrefBuildingX, afterXrefBuiltX HookXrefFunc) (err error)
- func FileExists(name string) bool
- func Get(key string) interface{}
- func GetBool(key string) bool
- func GetBoolP(prefix, key string) bool
- func GetBoolR(key string) bool
- func GetBoolRP(prefix, key string) bool
- func GetCurrentDir() string
- func GetDebugMode() bool
- func GetDuration(key string) time.Duration
- func GetDurationP(prefix, key string) time.Duration
- func GetDurationR(key string) time.Duration
- func GetDurationRP(prefix, key string) time.Duration
- func GetExcutableDir() string
- func GetExcutablePath() string
- func GetFloat32(key string) float32
- func GetFloat32P(prefix, key string) float32
- func GetFloat32R(key string) float32
- func GetFloat32RP(prefix, key string) float32
- func GetFloat64(key string) float64
- func GetFloat64P(prefix, key string) float64
- func GetFloat64R(key string) float64
- func GetFloat64RP(prefix, key string) float64
- func GetHierarchyList() map[string]interface{}
- func GetInt(key string) int
- func GetInt64(key string) int64
- func GetInt64P(prefix, key string) int64
- func GetInt64R(key string) int64
- func GetInt64RP(prefix, key string) int64
- func GetIntP(prefix, key string) int
- func GetIntR(key string) int
- func GetIntRP(prefix, key string) int
- func GetIntSlice(key string) []int
- func GetIntSliceP(prefix, key string) []int
- func GetIntSliceR(key string) []int
- func GetIntSliceRP(prefix, key string) []int
- func GetMap(key string) map[string]interface{}
- func GetMapR(key string) map[string]interface{}
- func GetPredefinedLocations() []string
- func GetQuietMode() bool
- func GetR(key string) interface{}
- func GetSectionFrom(sectionKeyPath string, holder interface{}) (err error)
- func GetStrictMode() bool
- func GetString(key string) string
- func GetStringP(prefix, key string) string
- func GetStringR(key string) string
- func GetStringRP(prefix, key string) string
- func GetStringSlice(key string) []string
- func GetStringSliceP(prefix, key string) []string
- func GetStringSliceR(key string) []string
- func GetStringSliceRP(prefix, key string) []string
- func GetUint(key string) uint
- func GetUint64(key string) uint64
- func GetUint64P(prefix, key string) uint64
- func GetUint64R(key string) uint64
- func GetUint64RP(prefix, key string) uint64
- func GetUintP(prefix, key string) uint
- func GetUintR(key string) uint
- func GetUintRP(prefix, key string) uint
- func GetUsedConfigFile() string
- func GetUsedConfigSubDir() string
- func GetVerboseMode() bool
- func InTesting() bool
- func InternalExecFor(rootCmd *RootCommand, args []string) (err error)
- func IsDigitHeavy(s string) bool
- func IsDirectory(path string) (bool, error)
- func IsRegularFile(path string) (bool, error)
- func Launch(cmd string, args ...string) (err error)
- func LaunchEditor(editor string) (content []byte, err error)
- func LaunchEditorWith(editor string, filename string) (content []byte, err error)
- func LoadConfigFile(file string) (err error)
- func MergeWith(m map[string]interface{}) (err error)
- func NormalizeDir(s string) string
- func PrintBuildInfo()
- func RemoveOnConfigLoadedListener(c ConfigReloaded)
- func ResetOptions()
- func SaveAsJSON(filename string) (err error)
- func SaveAsToml(filename string) (err error)
- func SaveAsYaml(filename string) (err error)
- func SaveObjAsToml(obj interface{}, filename string) (err error)
- func Set(key string, val interface{})
- func SetCurrentHelpPainter(painter Painter)
- func SetCustomShowBuildInfo(fn func())
- func SetCustomShowVersion(fn func())
- func SetHelpTabStop(tabStop int)
- func SetInternalOutputStreams(out, err *bufio.Writer)
- func SetNoLoadConfigFiles(b bool)
- func SetNx(key string, val interface{})
- func SetOnConfigLoadedListener(c ConfigReloaded, enabled bool)
- func SetPredefinedLocations(locations []string)
- func SetUnknownOptionHandler(handler func(isFlag bool, title string, cmd *Command, args []string))
- func Soundex(s string) (snd4 string)
- func StripOrderPrefix(s string) string
- func TrapSignals(onTrapped func(s os.Signal)) (waiter func())
- func WalkAllCommands(walk func(cmd *Command, index int) (err error)) (err error)
- func WrapWithRxxtPrefix(key string) string
- type BaseOpt
- func (s *BaseOpt) GetLongTitleNamesArray() []string
- func (s *BaseOpt) GetShortTitleNamesArray() []string
- func (s *BaseOpt) GetTitleName() string
- func (s *BaseOpt) GetTitleNames() string
- func (s *BaseOpt) GetTitleNamesArray() []string
- func (s *BaseOpt) GetTitleNamesBy(delimChar string) string
- func (s *BaseOpt) HasParent() bool
- type Command
- func (c *Command) GetExpandableNames() string
- func (c *Command) GetExpandableNamesArray() []string
- func (c *Command) GetHitStr() string
- func (c *Command) GetName() string
- func (c *Command) GetOwner() *Command
- func (c *Command) GetParentName() string
- func (c *Command) GetQuotedGroupName() string
- func (c *Command) GetRoot() *RootCommand
- func (c *Command) GetSubCommandNamesBy(delimChar string) string
- func (c *Command) IsRoot() bool
- func (c *Command) PrintHelp(justFlags bool)
- func (c *Command) PrintVersion()
- type ConfigReloaded
- type Copier
- type DistanceOption
- type ErrorForCmdr
- type Flag
- func (s *Flag) GetDescZsh() (desc string)
- func (s *Flag) GetTitleFlagNames() string
- func (s *Flag) GetTitleFlagNamesBy(delimChar string) string
- func (s *Flag) GetTitleFlagNamesByMax(delimChar string, maxCount int) string
- func (s *Flag) GetTitleZshFlagName() (str string)
- func (s *Flag) GetTitleZshFlagNames(delimChar string) (str string)
- func (s *Flag) GetTitleZshFlagNamesArray() (ary []string)
- type HookXrefFunc
- type OptCmd
- type OptFlag
- func NewBool() (opt OptFlag)
- func NewDuration() (opt OptFlag)
- func NewDurationFrom(flg *Flag) (opt OptFlag)
- func NewFloat32() (opt OptFlag)
- func NewFloat64() (opt OptFlag)
- func NewInt() (opt OptFlag)
- func NewInt64() (opt OptFlag)
- func NewIntSlice() (opt OptFlag)
- func NewString() (opt OptFlag)
- func NewStringSlice() (opt OptFlag)
- func NewUint() (opt OptFlag)
- func NewUint64() (opt OptFlag)
- type OptFlagType
- type Options
- func (s *Options) DumpAsString() (str string)
- func (s *Options) Get(key string) interface{}
- func (s *Options) GetBool(key string) (ret bool)
- func (s *Options) GetDuration(key string) (ir time.Duration)
- func (s *Options) GetFloat32(key string) (ir float32)
- func (s *Options) GetFloat64(key string) (ir float64)
- func (s *Options) GetHierarchyList() map[string]interface{}
- func (s *Options) GetInt(key string) (ir int64)
- func (s *Options) GetIntSlice(key string) (ir []int)
- func (s *Options) GetMap(key string) map[string]interface{}
- func (s *Options) GetString(key string) (ret string)
- func (s *Options) GetStringSlice(key string) (ir []string)
- func (s *Options) GetUint(key string) (ir uint64)
- func (s *Options) LoadConfigFile(file string) (err error)
- func (s *Options) MergeWith(m map[string]interface{}) (err error)
- func (s *Options) Reset()
- func (s *Options) Set(key string, val interface{})
- func (s *Options) SetNx(key string, val interface{})
- type Painter
- type RootCmdOpt
- func (s *RootCmdOpt) Action(action func(cmd *Command, args []string) (err error)) (opt OptCmd)
- func (s *RootCmdOpt) Aliases(aliases ...string) (opt OptCmd)
- func (s *RootCmdOpt) Bool() (opt OptFlag)
- func (s *RootCmdOpt) Copyright(copyright, author string) *RootCmdOpt
- func (s *RootCmdOpt) Deprecated(deprecation string) (opt OptCmd)
- func (s *RootCmdOpt) Description(oneLine, long string) (opt OptCmd)
- func (s *RootCmdOpt) Duration() (opt OptFlag)
- func (s *RootCmdOpt) Examples(examples string) (opt OptCmd)
- func (s *RootCmdOpt) Float32() (opt OptFlag)
- func (s *RootCmdOpt) Float64() (opt OptFlag)
- func (s *RootCmdOpt) Group(group string) (opt OptCmd)
- func (s *RootCmdOpt) Header(header string) *RootCmdOpt
- func (s *RootCmdOpt) Hidden(hidden bool) (opt OptCmd)
- func (s *RootCmdOpt) Int() (opt OptFlag)
- func (s *RootCmdOpt) Int64() (opt OptFlag)
- func (s *RootCmdOpt) IntSlice() (opt OptFlag)
- func (s *RootCmdOpt) Long(long string) (opt OptCmd)
- func (s *RootCmdOpt) NewFlag(typ OptFlagType) (opt OptFlag)
- func (s *RootCmdOpt) NewSubCommand() (opt OptCmd)
- func (s *RootCmdOpt) OwnerCommand() (opt OptCmd)
- func (s *RootCmdOpt) PostAction(pre func(cmd *Command, args []string)) (opt OptCmd)
- func (s *RootCmdOpt) PreAction(pre func(cmd *Command, args []string) (err error)) (opt OptCmd)
- func (s *RootCmdOpt) RootCommand() (root *RootCommand)
- func (s *RootCmdOpt) SetOwner(opt OptCmd)
- func (s *RootCmdOpt) Short(short string) (opt OptCmd)
- func (s *RootCmdOpt) String() (opt OptFlag)
- func (s *RootCmdOpt) StringSlice() (opt OptFlag)
- func (s *RootCmdOpt) TailPlaceholder(placeholder string) (opt OptCmd)
- func (s *RootCmdOpt) Titles(short, long string, aliases ...string) (opt OptCmd)
- func (s *RootCmdOpt) Uint() (opt OptFlag)
- func (s *RootCmdOpt) Uint64() (opt OptFlag)
- type RootCommand
- type StringDistance
Constants ¶
const ( // UnsortedGroup for commands and flags UnsortedGroup = "zzzz.unsorted" // SysMgmtGroup for commands and flags SysMgmtGroup = "zzz9.Misc" // DefaultEditor is 'vim' DefaultEditor = "vim" // ExternalToolEditor environment variable name, EDITOR is fit for most of shells. ExternalToolEditor = "EDITOR" // ExternalToolPasswordInput enables secure password input without echo. ExternalToolPasswordInput = "PASSWD" )
const ( // AppName const AppName = "cmdr" // main app-name // Version const Version = "1.1.7" // version name // VersionInt const VersionInt = 0x010107 // using as )
const ( // FgBlack terminal color code FgBlack = 30 // FgRed terminal color code FgRed = 31 // FgGreen terminal color code FgGreen = 32 // FgYellow terminal color code FgYellow = 33 // FgBlue terminal color code FgBlue = 34 // FgMagenta terminal color code FgMagenta = 35 // FgCyan terminal color code FgCyan = 36 // FgLightGray terminal color code FgLightGray = 37 // FgDarkGray terminal color code FgDarkGray = 90 // FgLightRed terminal color code FgLightRed = 91 // FgLightGreen terminal color code FgLightGreen = 92 // FgLightYellow terminal color code FgLightYellow = 93 // FgLightBlue terminal color code FgLightBlue = 94 // FgLightMagenta terminal color code FgLightMagenta = 95 // FgLightCyan terminal color code FgLightCyan = 96 // FgWhite terminal color code FgWhite = 97 // BgNormal terminal color code BgNormal = 0 // BgBoldOrBright terminal color code BgBoldOrBright = 1 // BgDim terminal color code BgDim = 2 // BgItalic terminal color code BgItalic = 3 // BgUnderline terminal color code BgUnderline = 4 // BgUlink terminal color code BgUlink = 5 // BgHidden terminal color code BgHidden = 8 // DarkColor terminal color code DarkColor = FgLightGray )
Variables ¶
var ( // GormDefaultCopier used for gorm GormDefaultCopier = &copierImpl{true, true, true} // StandardCopier is a normal copier StandardCopier = &copierImpl{false, false, false} )
var ( // EnableVersionCommands supports injecting the default `--version` flags and commands EnableVersionCommands = true // EnableHelpCommands supports injecting the default `--help` flags and commands EnableHelpCommands = true // EnableVerboseCommands supports injecting the default `--verbose` flags and commands EnableVerboseCommands = true // EnableCmdrCommands support these flags: `--strict-mode`, `--no-env-overrides` EnableCmdrCommands = true // EnableGenerateCommands supports injecting the default `generate` commands and subcommands EnableGenerateCommands = true // RxxtPrefix create a top-level namespace, which contains all normalized `Flag`s. RxxtPrefix = []string{"app"} // EnvPrefix attaches a prefix to key to retrieve the option value. EnvPrefix = []string{"CMDR"} // CurrentDescColor the print color for description line CurrentDescColor = FgDarkGray // CurrentDefaultValueColor the print color for default value line CurrentDefaultValueColor = FgDarkGray // CurrentGroupTitleColor the print color for titles CurrentGroupTitleColor = DarkColor // GetEditor sets callback to get editor program GetEditor func() (string, error) // ErrShouldBeStopException tips `Exec()` cancelled the following actions after `PreAction()` ErrShouldBeStopException = errors.New("should be stop right now") // ShouldIgnoreWrongEnumValue will be put into `cmdrError.Ignorable` while wrong enumerable value found in parsing command-line options. // main program might decide whether it's a warning or error. // see also: [Flag.ValidArgs] ShouldIgnoreWrongEnumValue = false )
var SavedOsArgs []string
SavedOsArgs is a copy of os.Args, just for testing
Functions ¶
func AddOnAfterXrefBuilt ¶ added in v0.2.11
func AddOnAfterXrefBuilt(cb HookXrefFunc)
AddOnAfterXrefBuilt add hook func
func AddOnBeforeXrefBuilding ¶ added in v0.2.11
func AddOnBeforeXrefBuilding(cb HookXrefFunc)
AddOnBeforeXrefBuilding add hook func
func AddOnConfigLoadedListener ¶
func AddOnConfigLoadedListener(c ConfigReloaded)
AddOnConfigLoadedListener add an functor on config loaded and merged
func AsJSON ¶ added in v1.1.1
func AsJSON() (b []byte)
AsJSON returns a json string bytes about all options
func AsToml ¶ added in v1.1.1
func AsToml() (b []byte)
AsToml returns a toml string bytes about all options
func AsYaml ¶ added in v1.1.1
func AsYaml() (b []byte)
AsYaml returns a yaml string bytes about all options
func Clone ¶ added in v0.2.3
func Clone(fromValue, toValue interface{}) interface{}
Clone deep copy source to target
func ExecWith ¶ added in v0.2.11
func ExecWith(rootCmd *RootCommand, beforeXrefBuildingX, afterXrefBuiltX HookXrefFunc) (err error)
ExecWith is main entry of `cmdr`.
func FileExists ¶
FileExists returns the existence of an directory or file
func Get ¶
func Get(key string) interface{}
Get returns the generic value of an `Option` key with WrapWithRxxtPrefix. Such as: ```golang cmdr.Get("app.logger.level") => 'DEBUG',... ```
func GetBool ¶
GetBool returns the bool value of an `Option` key. Such as: ```golang cmdr.Get("app.logger.enable") => true,... ```
func GetBoolP ¶ added in v0.2.3
GetBoolP returns the bool value of an `Option` key. Such as: ```golang cmdr.GetP("app.logger", "enable") => true,... ```
func GetBoolR ¶ added in v0.2.23
GetBoolR returns the bool value of an `Option` key with WrapWithRxxtPrefix. Such as: ```golang cmdr.GetBoolR("logger.enable") => true,... ```
func GetBoolRP ¶ added in v0.2.23
GetBoolRP returns the bool value of an `Option` key with WrapWithRxxtPrefix. Such as: ```golang cmdr.GetBoolRP("logger", "enable") => true,... ```
func GetCurrentDir ¶
func GetCurrentDir() string
GetCurrentDir returns the current workingFlag directory
func GetDebugMode ¶ added in v0.2.5
func GetDebugMode() bool
GetDebugMode returns the flag value of `--debug`/`-D`
func GetDuration ¶ added in v0.2.19
GetDuration returns the int slice value of an `Option` key.
func GetDurationP ¶ added in v0.2.19
GetDurationP returns the int slice value of an `Option` key.
func GetDurationR ¶ added in v1.0.0
GetDurationR returns the int slice value of an `Option` key.
func GetDurationRP ¶ added in v1.0.0
GetDurationRP returns the int slice value of an `Option` key.
func GetExcutableDir ¶
func GetExcutableDir() string
GetExcutableDir returns the executable file directory
func GetExcutablePath ¶ added in v0.2.13
func GetExcutablePath() string
GetExcutablePath returns the executable file path
func GetFloat32 ¶ added in v1.0.1
GetFloat32 returns the float32 value of an `Option` key.
func GetFloat32P ¶ added in v1.0.1
GetFloat32P returns the float32 value of an `Option` key.
func GetFloat32R ¶ added in v1.0.1
GetFloat32R returns the float32 value of an `Option` key with WrapWithRxxtPrefix.
func GetFloat32RP ¶ added in v1.0.1
GetFloat32RP returns the float32 value of an `Option` key with WrapWithRxxtPrefix.
func GetFloat64 ¶ added in v1.0.1
GetFloat64 returns the float64 value of an `Option` key.
func GetFloat64P ¶ added in v1.0.1
GetFloat64P returns the float64 value of an `Option` key.
func GetFloat64R ¶ added in v1.0.1
GetFloat64R returns the float64 value of an `Option` key with WrapWithRxxtPrefix.
func GetFloat64RP ¶ added in v1.0.1
GetFloat64RP returns the float64 value of an `Option` key with WrapWithRxxtPrefix.
func GetHierarchyList ¶ added in v1.1.1
func GetHierarchyList() map[string]interface{}
GetHierarchyList returns the hierarchy data
func GetInt64R ¶ added in v0.2.23
GetInt64R returns the int64 value of an `Option` key with WrapWithRxxtPrefix.
func GetInt64RP ¶ added in v0.2.23
GetInt64RP returns the int64 value of an `Option` key with WrapWithRxxtPrefix.
func GetIntR ¶ added in v0.2.23
GetIntR returns the int value of an `Option` key with WrapWithRxxtPrefix.
func GetIntRP ¶ added in v0.2.23
GetIntRP returns the int value of an `Option` key with WrapWithRxxtPrefix.
func GetIntSlice ¶ added in v0.2.19
GetIntSlice returns the int slice value of an `Option` key.
func GetIntSliceP ¶ added in v0.2.19
GetIntSliceP returns the int slice value of an `Option` key.
func GetIntSliceR ¶ added in v0.2.23
GetIntSliceR returns the int slice value of an `Option` key with WrapWithRxxtPrefix.
func GetIntSliceRP ¶ added in v0.2.23
GetIntSliceRP returns the int slice value of an `Option` key with WrapWithRxxtPrefix.
func GetMapR ¶ added in v1.0.0
GetMapR an `Option` by key string with WrapWithRxxtPrefix, it returns a hierarchy map or nil
func GetPredefinedLocations ¶ added in v0.2.5
func GetPredefinedLocations() []string
GetPredefinedLocations return the searching locations for loading config files.
func GetQuietMode ¶ added in v0.2.5
func GetQuietMode() bool
GetQuietMode returns the flag value of `--quiet`/`-q`
func GetR ¶ added in v0.2.23
func GetR(key string) interface{}
GetR returns the generic value of an `Option` key with WrapWithRxxtPrefix. Such as: ```golang cmdr.GetR("logger.level") => 'DEBUG',... ```
func GetSectionFrom ¶ added in v1.0.1
GetSectionFrom returns error while cannot yaml Marshal and Unmarshal `cmdr.GetSectionFrom(sectionKeyPath, &holder)` could load all sub-tree nodes from sectionKeyPath and transform them into holder structure, such as: ```go
type ServerConfig struct { Port int HttpMode int EnableTls bool } var serverConfig = new(ServerConfig) cmdr.GetSectionFrom("server", &serverConfig) assert serverConfig.Port == 7100
```
func GetStrictMode ¶ added in v0.2.5
func GetStrictMode() bool
GetStrictMode enables error when opt value missed. such as: xxx a b --prefix” => error: prefix opt has no value specified. xxx a b --prefix'/' => ok.
ENV: use `CMDR_APP_STRICT_MODE=true` to enable strict-mode. NOTE: `CMDR_APP_` prefix could be set by user (via: `EnvPrefix` && `RxxtPrefix`).
the flag value of `--strict-mode`.
func GetStringP ¶ added in v0.2.3
GetStringP returns the string value of an `Option` key.
func GetStringR ¶ added in v0.2.23
GetStringR returns the string value of an `Option` key with WrapWithRxxtPrefix.
func GetStringRP ¶ added in v0.2.23
GetStringRP returns the string value of an `Option` key with WrapWithRxxtPrefix.
func GetStringSlice ¶
GetStringSlice returns the string slice value of an `Option` key.
func GetStringSliceP ¶ added in v0.2.3
GetStringSliceP returns the string slice value of an `Option` key.
func GetStringSliceR ¶ added in v0.2.23
GetStringSliceR returns the string slice value of an `Option` key with WrapWithRxxtPrefix.
func GetStringSliceRP ¶ added in v0.2.23
GetStringSliceRP returns the string slice value of an `Option` key with WrapWithRxxtPrefix.
func GetUint64P ¶ added in v0.2.3
GetUint64P returns the uint64 value of an `Option` key.
func GetUint64R ¶ added in v0.2.23
GetUint64R returns the uint64 value of an `Option` key with WrapWithRxxtPrefix.
func GetUint64RP ¶ added in v0.2.23
GetUint64RP returns the uint64 value of an `Option` key with WrapWithRxxtPrefix.
func GetUintR ¶ added in v0.2.23
GetUintR returns the uint value of an `Option` key with WrapWithRxxtPrefix.
func GetUintRP ¶ added in v0.2.23
GetUintRP returns the uint value of an `Option` key with WrapWithRxxtPrefix.
func GetUsedConfigFile ¶ added in v0.2.3
func GetUsedConfigFile() string
GetUsedConfigFile returns the main config filename (generally it's `<appname>.yml`)
func GetUsedConfigSubDir ¶ added in v0.2.3
func GetUsedConfigSubDir() string
GetUsedConfigSubDir returns the sub-directory `conf.d` of config files. Note that it be always normalized now. Sometimes it might be empty string ("") if `conf.d` have not been found.
func GetVerboseMode ¶ added in v0.2.5
func GetVerboseMode() bool
GetVerboseMode returns the flag value of `--verbose`/`-v`
func InTesting ¶ added in v0.2.19
func InTesting() bool
InTesting detects whether is running under go test mode
func InternalExecFor ¶ added in v0.2.3
func InternalExecFor(rootCmd *RootCommand, args []string) (err error)
InternalExecFor is an internal helper, esp for debugging
func IsDigitHeavy ¶ added in v1.0.2
IsDigitHeavy tests if the whole string is digit
func IsDirectory ¶ added in v0.2.21
IsDirectory tests whether `path` is a directory or not
func IsRegularFile ¶ added in v0.2.21
IsRegularFile tests whether `path` is a normal regular file or not
func Launch ¶ added in v0.2.13
Launch executes a command setting both standard input, output and error.
func LaunchEditor ¶ added in v0.2.13
LaunchEditor launches the specified editor
func LaunchEditorWith ¶ added in v0.2.19
LaunchEditorWith launches the specified editor with a filename
func LoadConfigFile ¶
LoadConfigFile Load a yaml config file and merge the settings into `rxxtOptions` and load files in the `conf.d` child directory too.
func MergeWith ¶ added in v1.1.4
MergeWith will merge a map recursive. You could merge a yaml/json/toml options into cmdr Hierarchy Options.
func NormalizeDir ¶ added in v0.2.19
NormalizeDir make dir name normalized
func PrintBuildInfo ¶ added in v0.2.19
func PrintBuildInfo()
PrintBuildInfo print building information
func RemoveOnConfigLoadedListener ¶
func RemoveOnConfigLoadedListener(c ConfigReloaded)
RemoveOnConfigLoadedListener remove an functor on config loaded and merged
func ResetOptions ¶ added in v0.2.19
func ResetOptions()
ResetOptions to reset the exists `Options`, so that you could follow a `LoadConfigFile()` with it.
func SaveAsJSON ¶ added in v0.2.17
SaveAsJSON to Save all config entries as a json file
func SaveAsToml ¶ added in v0.2.17
SaveAsToml to Save all config entries as a toml file
func SaveAsYaml ¶ added in v0.2.17
SaveAsYaml to Save all config entries as a yaml file
func SaveObjAsToml ¶ added in v0.2.19
SaveObjAsToml to Save an object as a toml file
func Set ¶ added in v0.2.3
func Set(key string, val interface{})
Set set the value of an `Option` key (with prefix auto-wrap). The key MUST not have an `app` prefix. eg:
cmdr.Set("logger.level", "DEBUG") cmdr.Set("ms.tags.port", 8500) ... cmdr.Set("debug", true) cmdr.GetBool("app.debug") => true
func SetCurrentHelpPainter ¶ added in v0.2.23
func SetCurrentHelpPainter(painter Painter)
SetCurrentHelpPainter allows to change the behavior and facade of help screen.
func SetCustomShowBuildInfo ¶ added in v0.2.3
func SetCustomShowBuildInfo(fn func())
SetCustomShowBuildInfo supports your `ShowBuildInfo()` instead of internal `showBuildInfo()`
func SetCustomShowVersion ¶ added in v0.2.3
func SetCustomShowVersion(fn func())
SetCustomShowVersion supports your `ShowVersion()` instead of internal `showVersion()`
func SetHelpTabStop ¶ added in v1.0.0
func SetHelpTabStop(tabStop int)
SetHelpTabStop sets the tab stop for help screen output
func SetInternalOutputStreams ¶ added in v0.2.3
SetInternalOutputStreams sets the internal output streams for debugging
func SetNoLoadConfigFiles ¶ added in v0.2.21
func SetNoLoadConfigFiles(b bool)
SetNoLoadConfigFiles true means no loading config files
func SetNx ¶ added in v0.2.3
func SetNx(key string, val interface{})
SetNx but without prefix auto-wrapped. `rxxtPrefix` is a string slice to define the prefix string array, default is ["app"]. So, cmdr.Set("debug", true) will put an real entry with (`app.debug`, true).
func SetOnConfigLoadedListener ¶
func SetOnConfigLoadedListener(c ConfigReloaded, enabled bool)
SetOnConfigLoadedListener enable/disable an functor on config loaded and merged
func SetPredefinedLocations ¶ added in v0.2.5
func SetPredefinedLocations(locations []string)
SetPredefinedLocations to customize the searching locations for loading config files. It MUST be invoked before `cmdr.Exec`. Such as: ```go
SetPredefinedLocations([]string{"./config", "~/.config/cmdr/", "$GOPATH/running-configs/cmdr"})
```
func SetUnknownOptionHandler ¶ added in v0.2.23
SetUnknownOptionHandler enables your customized wrong command/flag processor. internal processor supports smart suggestions for those wrong commands and flags.
func Soundex ¶ added in v0.2.25
Soundex returns the english word's soundex value, such as: 'tags' => 't322'
func StripOrderPrefix ¶ added in v0.2.9
StripOrderPrefix strips the prefix string fragment for sorting order. see also: Command.Group, Flag.Group, ...
func TrapSignals ¶ added in v1.1.7
TrapSignals is a helper for simplify your infinite loop codes.
Usage
func aLoop() { waiter := trapSignals(func(s os.Signal) { logrus.Debugf("receive signal '%v' in onTrapped()", s) }) go waiter() }
func WalkAllCommands ¶ added in v0.2.9
WalkAllCommands loops for all commands, starting from root.
func WrapWithRxxtPrefix ¶ added in v0.2.23
WrapWithRxxtPrefix wrap an key with RxxtPrefix, for [GetXxx(key)] and [GetXxxP(prefix,key)]
Types ¶
type BaseOpt ¶
type BaseOpt struct { Name string // Short rune. short option/command name. // single char. example for flag: "a" -> "-a" Short string // Full full/long option/command name. // word string. example for flag: "addr" -> "--addr" Full string // Aliases are the more synonyms Aliases []string // Group group name Group string Description string LongDescription string Examples string Hidden bool // Deprecated is a version string just like '0.5.9', that means this command/flag was/will be deprecated since `v0.5.9`. Deprecated string // Action is callback for the last recognized command/sub-command. // return: ErrShouldBeStopException will break the following flow and exit right now // cmd 是 flag 被识别时已经得到的子命令 Action func(cmd *Command, args []string) (err error) // contains filtered or unexported fields }
BaseOpt is base of `Command`, `Flag`
func (*BaseOpt) GetLongTitleNamesArray ¶ added in v0.2.3
GetLongTitleNamesArray returns long name and aliases as an array
func (*BaseOpt) GetShortTitleNamesArray ¶ added in v0.2.3
GetShortTitleNamesArray returns short name as an array
func (*BaseOpt) GetTitleName ¶
GetTitleName returns name/full/short string
func (*BaseOpt) GetTitleNames ¶
GetTitleNames return the joint string of short,full,aliases names
func (*BaseOpt) GetTitleNamesArray ¶
GetTitleNamesArray returns short,full,aliases names
func (*BaseOpt) GetTitleNamesBy ¶
GetTitleNamesBy returns the joint string of short,full,aliases names
type Command ¶
type Command struct { BaseOpt Flags []*Flag SubCommands []*Command // return: ErrShouldBeStopException will break the following flow and exit right now PreAction func(cmd *Command, args []string) (err error) // PostAction will be run after Action() invoked. PostAction func(cmd *Command, args []string) // be shown at tail of command usages line. Such as for TailPlaceHolder="<host-fqdn> <ipv4/6>": // austr dns add <host-fqdn> <ipv4/6> [Options] [Parent/Global Options] TailPlaceHolder string // contains filtered or unexported fields }
Command holds the structure of commands and subcommands
func FindSubCommand ¶ added in v0.2.17
FindSubCommand find sub-command with `longName` from `cmd`
func FindSubCommandRecursive ¶ added in v0.2.17
FindSubCommandRecursive find sub-command with `longName` from `cmd` recursively
func (*Command) GetExpandableNames ¶
GetExpandableNames returns the names comma splitted string.
func (*Command) GetExpandableNamesArray ¶
GetExpandableNamesArray returns the names array of command, includes short name and long name.
func (*Command) GetParentName ¶
GetParentName returns the owner command name
func (*Command) GetQuotedGroupName ¶
GetQuotedGroupName returns the group name quoted string.
func (*Command) GetRoot ¶
func (c *Command) GetRoot() *RootCommand
GetRoot returns the `RootCommand`
func (*Command) GetSubCommandNamesBy ¶
GetSubCommandNamesBy returns the joint string of subcommands
func (*Command) PrintVersion ¶
func (c *Command) PrintVersion()
PrintVersion prints versions information
type ConfigReloaded ¶
type ConfigReloaded interface {
OnConfigReloaded()
}
ConfigReloaded for config reloaded
type Copier ¶ added in v0.2.3
type Copier interface {
Copy(toValue interface{}, fromValue interface{}, ignoreNames ...string) (err error)
}
Copier interface Copier is based on from github.com/jinzhu/copier
type DistanceOption ¶ added in v1.1.3
type DistanceOption func(StringDistance)
DistanceOption is a functional options prototype
func JWWithThreshold ¶ added in v1.1.3
func JWWithThreshold(threshold float64) DistanceOption
JWWithThreshold sets the threshold for Jaro-Winkler algorithm.
type ErrorForCmdr ¶ added in v1.0.2
ErrorForCmdr structure
func NewError ¶ added in v1.0.2
func NewError(ignorable bool, inner error, args ...interface{}) *ErrorForCmdr
NewError formats a ErrorForCmdr object
func NewErrorWithMsg ¶ added in v1.0.2
func NewErrorWithMsg(msg string, inner error) *ErrorForCmdr
NewErrorWithMsg formats a ErrorForCmdr object
func (*ErrorForCmdr) Error ¶ added in v1.0.2
func (s *ErrorForCmdr) Error() string
type Flag ¶
type Flag struct { BaseOpt // ToggleGroup: to-do: Toggle Group ToggleGroup string // DefaultValuePlaceholder for flag DefaultValuePlaceholder string // DefaultValue default value for flag DefaultValue interface{} // ValidArgs to-do ValidArgs []string // Required to-do Required bool // ExternalTool to get the value text by invoking external tool // It's an environment variable name, such as: "EDITOR" (or cmdr.ExternalToolEditor) ExternalTool string // HeadLike enables a free-hand option like `head -3`. // // When a free-hand option presents, it'll be treated as a named option with an integer value. // // For example, option/flag = `{{Full:"line",Short:"l"},HeadLike:true}`, the command line: // `app -3` // is equivalent to `app -l 3`, and so on. // // HeadLike assumed an named option with an integer value, that means, Min and Max can be applied on it too. // NOTE: Only one head-like option can be defined in a command/sub-command chain. HeadLike bool // Min minimal value of a range. Min int64 // Max maximal value of a range. Max int64 // PostAction treat this flag as a command! PostAction func(cmd *Command, args []string) (err error) // contains filtered or unexported fields }
Flag means a flag, a option, or a opt.
func FindFlagRecursive ¶ added in v0.2.17
FindFlagRecursive find flag with `longName` from `cmd` recursively
func (*Flag) GetDescZsh ¶ added in v0.2.13
GetDescZsh temp
func (*Flag) GetTitleFlagNames ¶ added in v0.2.13
GetTitleFlagNames temp
func (*Flag) GetTitleFlagNamesBy ¶ added in v0.2.13
GetTitleFlagNamesBy temp
func (*Flag) GetTitleFlagNamesByMax ¶ added in v0.2.13
GetTitleFlagNamesByMax temp
func (*Flag) GetTitleZshFlagName ¶ added in v0.2.13
GetTitleZshFlagName temp
func (*Flag) GetTitleZshFlagNames ¶ added in v0.2.13
GetTitleZshFlagNames temp
func (*Flag) GetTitleZshFlagNamesArray ¶ added in v0.2.13
GetTitleZshFlagNamesArray temp
type HookXrefFunc ¶ added in v0.2.11
type HookXrefFunc func(root *RootCommand, args []string)
HookXrefFunc the hook function prototype for SetBeforeXrefBuilding and SetAfterXrefBuilt
type OptCmd ¶ added in v0.2.15
type OptCmd interface { Titles(short, long string, aliases ...string) (opt OptCmd) Short(short string) (opt OptCmd) Long(long string) (opt OptCmd) Aliases(ss ...string) (opt OptCmd) Description(oneLine, long string) (opt OptCmd) Examples(examples string) (opt OptCmd) Group(group string) (opt OptCmd) Hidden(hidden bool) (opt OptCmd) Deprecated(deprecation string) (opt OptCmd) Action(action func(cmd *Command, args []string) (err error)) (opt OptCmd) // FlagAdd(flg *Flag) (opt OptCmd) // SubCommand(cmd *Command) (opt OptCmd) PreAction(pre func(cmd *Command, args []string) (err error)) (opt OptCmd) PostAction(post func(cmd *Command, args []string)) (opt OptCmd) TailPlaceholder(placeholder string) (opt OptCmd) NewFlag(typ OptFlagType) (opt OptFlag) NewSubCommand() (opt OptCmd) OwnerCommand() (opt OptCmd) SetOwner(opt OptCmd) RootCommand() *RootCommand }
OptCmd to support fluent api of cmdr. see also: cmdr.Root().NewSubCommand()/.NewFlag()
func NewCmdFrom ¶ added in v0.2.17
NewCmdFrom for fluent api
type OptFlag ¶ added in v0.2.15
type OptFlag interface { Titles(short, long string, aliases ...string) (opt OptFlag) Short(short string) (opt OptFlag) Long(long string) (opt OptFlag) Aliases(ss ...string) (opt OptFlag) Description(oneLine, long string) (opt OptFlag) Examples(examples string) (opt OptFlag) Group(group string) (opt OptFlag) Hidden(hidden bool) (opt OptFlag) Deprecated(deprecation string) (opt OptFlag) Action(action func(cmd *Command, args []string) (err error)) (opt OptFlag) ToggleGroup(group string) (opt OptFlag) DefaultValue(val interface{}, placeholder string) (opt OptFlag) ExternalTool(envKeyName string) (opt OptFlag) ValidArgs(list ...string) (opt OptFlag) // HeadLike enables `head -n` mode. // min, max will be ignored at this version, its might be impl in the future HeadLike(enable bool, min, max int64) (opt OptFlag) OnSet(func(keyPath string, value interface{})) (opt OptFlag) OwnerCommand() (opt OptCmd) SetOwner(opt OptCmd) RootCommand() *RootCommand }
OptFlag to support fluent api of cmdr. see also: cmdr.Root().NewSubCommand()/.NewFlag()
func NewDurationFrom ¶ added in v1.0.3
NewDurationFrom for fluent api
func NewStringSlice ¶ added in v0.2.17
func NewStringSlice() (opt OptFlag)
NewStringSlice for fluent api
type OptFlagType ¶ added in v0.2.15
type OptFlagType int
OptFlagType to support fluent api of cmdr. see also: OptCmd.NewFlag(OptFlagType)
Usage
root := cmdr.Root() co := root.NewSubCommand() co.NewFlag(cmdr.OptFlagTypeUint)
See also those short-hand constructors: Bool(), Int(), ....
const ( // OptFlagTypeBool to create a new bool flag OptFlagTypeBool OptFlagType = iota // OptFlagTypeInt to create a new int flag OptFlagTypeInt OptFlagType = iota + 1 // OptFlagTypeUint to create a new uint flag OptFlagTypeUint OptFlagType = iota + 2 // OptFlagTypeInt64 to create a new int64 flag OptFlagTypeInt64 OptFlagType = iota + 3 // OptFlagTypeUint64 to create a new uint64 flag OptFlagTypeUint64 OptFlagType = iota + 4 // OptFlagTypeString to create a new string flag OptFlagTypeString OptFlagType = iota + 5 // OptFlagTypeStringSlice to create a new string slice flag OptFlagTypeStringSlice OptFlagType = iota + 6 // OptFlagTypeIntSlice to create a new int slice flag OptFlagTypeIntSlice OptFlagType = iota + 7 // OptFlagTypeFloat32 to create a new int float32 flag OptFlagTypeFloat32 OptFlagType = iota + 8 // OptFlagTypeFloat64 to create a new int float64 flag OptFlagTypeFloat64 OptFlagType = iota + 9 // OptFlagTypeDuration to create a new duration flag OptFlagTypeDuration OptFlagType = iota + 10 )
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options is a holder of all options
func NewOptionsWith ¶
NewOptionsWith returns an `Options` structure pointer
func (*Options) DumpAsString ¶
DumpAsString for debugging.
func (*Options) Get ¶
Get an `Option` by key string, eg: ```golang cmdr.Get("app.logger.level") => 'DEBUG',... ```
func (*Options) GetDuration ¶ added in v0.2.11
GetDuration returns the time duration value of an `Option` key.
func (*Options) GetFloat32 ¶ added in v1.0.1
GetFloat32 returns the float32 value of an `Option` key.
func (*Options) GetFloat64 ¶ added in v1.0.1
GetFloat64 returns the float64 value of an `Option` key.
func (*Options) GetHierarchyList ¶ added in v0.2.17
GetHierarchyList returns the hierarchy data for dumping
func (*Options) GetIntSlice ¶ added in v0.2.11
GetIntSlice returns the string slice value of an `Option` key.
func (*Options) GetMap ¶ added in v1.0.0
GetMap an `Option` by key string, it returns a hierarchy map or nil
func (*Options) GetStringSlice ¶
GetStringSlice returns the string slice value of an `Option` key.
func (*Options) LoadConfigFile ¶
LoadConfigFile Load a yaml config file and merge the settings into `rxxtOptions` and load files in the `conf.d` child directory too.
func (*Options) Reset ¶
func (s *Options) Reset()
Reset the exists `Options`, so that you could follow a `LoadConfigFile()` with it.
type Painter ¶ added in v0.2.9
type Painter interface { Printf(fmtStr string, args ...interface{}) FpPrintHeader(command *Command) FpPrintHelpTailLine(command *Command) FpUsagesTitle(command *Command, title string) FpUsagesLine(command *Command, fmt, appName, cmdList, cmdsTitle, tailPlaceHolder string) FpDescTitle(command *Command, title string) FpDescLine(command *Command) FpExamplesTitle(command *Command, title string) FpExamplesLine(command *Command) FpCommandsTitle(command *Command) FpCommandsGroupTitle(group string) FpCommandsLine(command *Command) FpFlagsTitle(command *Command, flag *Flag, title string) FpFlagsGroupTitle(group string) FpFlagsLine(command *Command, flag *Flag, defValStr string) Flush() Results() []byte // clear any internal states and reset itself Reset() }
Painter to support the genManual, genMarkdown, printHelpScreen.
type RootCmdOpt ¶ added in v0.2.15
type RootCmdOpt struct {
// contains filtered or unexported fields
}
RootCmdOpt for fluent api
func Root ¶ added in v0.2.15
func Root(appName, version string) (opt *RootCmdOpt)
Root for fluent api, to create a new *RootCmdOpt object.
func RootFrom ¶ added in v1.0.3
func RootFrom(root *RootCommand) (opt *RootCmdOpt)
RootFrom for fluent api, to create the new *RootCmdOpt object from an existed RootCommand
func (*RootCmdOpt) Copyright ¶ added in v0.2.15
func (s *RootCmdOpt) Copyright(copyright, author string) *RootCmdOpt
Copyright for fluent api
func (*RootCmdOpt) Deprecated ¶ added in v0.2.15
func (*RootCmdOpt) Description ¶ added in v0.2.15
func (*RootCmdOpt) Header ¶ added in v0.2.15
func (s *RootCmdOpt) Header(header string) *RootCmdOpt
Header for fluent api
func (*RootCmdOpt) NewFlag ¶ added in v0.2.15
func (s *RootCmdOpt) NewFlag(typ OptFlagType) (opt OptFlag)
func (*RootCmdOpt) NewSubCommand ¶ added in v0.2.15
func (s *RootCmdOpt) NewSubCommand() (opt OptCmd)
func (*RootCmdOpt) OwnerCommand ¶ added in v0.2.15
func (s *RootCmdOpt) OwnerCommand() (opt OptCmd)
func (*RootCmdOpt) PostAction ¶ added in v0.2.15
func (*RootCmdOpt) RootCommand ¶ added in v0.2.15
func (s *RootCmdOpt) RootCommand() (root *RootCommand)
func (*RootCmdOpt) StringSlice ¶ added in v0.2.15
func (s *RootCmdOpt) StringSlice() (opt OptFlag)
func (*RootCmdOpt) TailPlaceholder ¶ added in v0.2.15
type RootCommand ¶
type RootCommand struct { Command AppName string Version string VersionInt uint32 Copyright string Author string Header string // using `Header` for header and ignore built with `Copyright` and `Author`, and no usage lines too. // contains filtered or unexported fields }
RootCommand holds some application information
type StringDistance ¶ added in v1.1.3
type StringDistance interface {
Calc(s1, s2 string, opts ...DistanceOption) (distance int)
}
StringDistance is an interface for string metric. A string metric is a metric that measures distance between two strings. In most case, it means that the edit distance about those two strings. This is saying, it is how many times are needed while you were modifying string to another one, note that inserting, deleting, substing one character means once.
func JaroWinklerDistance ¶ added in v1.1.3
func JaroWinklerDistance(opts ...DistanceOption) StringDistance
JaroWinklerDistance returns an calculator for two strings distance metric, with Jaro-Winkler algorithm.
Source Files ¶
- base_opt.go
- build_xref.go
- clone.go
- command.go
- def.go
- dir.go
- doc.go
- exec.go
- exec_match.go
- exec_unknown.go
- flag.go
- fs_wrap.go
- generate_cmds.go
- generate_shell.go
- opt.go
- opt_command_impl.go
- opt_flag_impl.go
- opt_ops.go
- options.go
- options.watch.go
- print.go
- print_colors.go
- print_painter.go
- print_painter_help.go
- print_painter_man.go
- print_painter_mkd.go
- print_tree.go
- sc_wrap.go
- term_wrap.go
- tool.go
- walk.go
- whitespaces.go