cmdr: github.com/hedzr/cmdr Index | Files | Directories

package cmdr

import "github.com/hedzr/cmdr"

Index

Package Files

base_opt.go build_xref.go clone.go command.go def.go deprecated.go dir.go doc.go exec.go exec_match.go exec_unknown.go exec_with_options.go flag.go fs_wrap.go generate_cmds.go generate_shell.go log.go opt.go opt_command_impl.go opt_flag_impl.go opt_ops.go options.go options_cvt.go options_watch.go predefined_locations.go print.go print_colors.go print_painter.go print_painter_help.go print_painter_man.go print_painter_mkd.go print_tree.go ptpkg.go sc_wrap.go term_wrap.go tool.go types.go walk.go whitespaces.go

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"
    // Version const
    Version = "1.6.1"
    // VersionInt const
    VersionInt = 0x010601
)
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 (

    // 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

    // ErrShouldBeStopException tips `Exec()` cancelled the following actions after `PreAction()`
    ErrShouldBeStopException = errors.New("should be stop right now")
)
var SavedOsArgs []string

SavedOsArgs is a copy of os.Args, just for testing

func AddOnConfigLoadedListener Uses

func AddOnConfigLoadedListener(c ConfigReloaded)

AddOnConfigLoadedListener adds an functor on config loaded and merged

func AsJSON Uses

func AsJSON() (b []byte)

AsJSON returns a json string bytes about all options

func AsToml Uses

func AsToml() (b []byte)

AsToml returns a toml string bytes about all options

func AsYaml Uses

func AsYaml() (b []byte)

AsYaml returns a yaml string bytes about all options

func Clone Uses

func Clone(fromValue, toValue interface{}) interface{}

Clone deep copy source to target

func DumpAsString Uses

func DumpAsString() (str string)

DumpAsString for debugging.

func EnsureDir Uses

func EnsureDir(dir string) (err error)

EnsureDir checks and creates the directory.

func Exec Uses

func Exec(rootCmd *RootCommand, opts ...ExecOption) (err error)

Exec is main entry of `cmdr`.

func FileExists Uses

func FileExists(name string) bool

FileExists returns the existence of an directory or file

func Get Uses

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 Uses

func GetBool(key string) bool

GetBool returns the bool value of an `Option` key. Such as: “`golang cmdr.GetBool("app.logger.enable") => true,... “`

func GetBoolEx Uses

func GetBoolEx(key string, defaultVal bool) bool

GetBoolEx returns the bool value of an `Option` key. Such as: “`golang cmdr.GetBoolEx("app.logger.enable", false) => true,... “`

func GetBoolExP Uses

func GetBoolExP(prefix, key string, defaultVal bool) bool

GetBoolExP returns the bool value of an `Option` key. Such as: “`golang cmdr.GetBoolExP("app.logger", "enable", false) => true,... “`

func GetBoolExR Uses

func GetBoolExR(key string, defaultVal bool) bool

GetBoolExR returns the bool value of an `Option` key with [WrapWithRxxtPrefix]. Such as: “`golang cmdr.GetBoolExR("logger.enable", false) => true,... “`

func GetBoolExRP Uses

func GetBoolExRP(prefix, key string, defaultVal bool) bool

GetBoolExRP returns the bool value of an `Option` key with [WrapWithRxxtPrefix]. Such as: “`golang cmdr.GetBoolExRP("logger", "enable", false) => true,... “`

func GetBoolP Uses

func GetBoolP(prefix, key string) bool

GetBoolP returns the bool value of an `Option` key. Such as: “`golang cmdr.GetBoolP("app.logger", "enable") => true,... “`

func GetBoolR Uses

func GetBoolR(key string) bool

GetBoolR returns the bool value of an `Option` key with [WrapWithRxxtPrefix]. Such as: “`golang cmdr.GetBoolR("logger.enable") => true,... “`

func GetBoolRP Uses

func GetBoolRP(prefix, key string) bool

GetBoolRP returns the bool value of an `Option` key with [WrapWithRxxtPrefix]. Such as: “`golang cmdr.GetBoolRP("logger", "enable") => true,... “`

func GetCurrentDir Uses

func GetCurrentDir() string

GetCurrentDir returns the current workingFlag directory it should be equal with os.Getenv("PWD")

func GetDebugMode Uses

func GetDebugMode() bool

GetDebugMode returns the flag value of `--debug`/`-D`

func GetDuration Uses

func GetDuration(key string) time.Duration

GetDuration returns the int slice value of an `Option` key.

func GetDurationEx Uses

func GetDurationEx(key string, defaultVal time.Duration) time.Duration

GetDurationEx returns the int slice value of an `Option` key.

func GetDurationExP Uses

func GetDurationExP(prefix, key string, defaultVal time.Duration) time.Duration

GetDurationExP returns the int slice value of an `Option` key.

func GetDurationExR Uses

func GetDurationExR(key string, defaultVal time.Duration) time.Duration

GetDurationExR returns the int slice value of an `Option` key.

func GetDurationExRP Uses

func GetDurationExRP(prefix, key string, defaultVal time.Duration) time.Duration

GetDurationExRP returns the int slice value of an `Option` key.

func GetDurationP Uses

func GetDurationP(prefix, key string) time.Duration

GetDurationP returns the int slice value of an `Option` key.

func GetDurationR Uses

func GetDurationR(key string) time.Duration

GetDurationR returns the int slice value of an `Option` key.

func GetDurationRP Uses

func GetDurationRP(prefix, key string) time.Duration

GetDurationRP returns the int slice value of an `Option` key.

func GetExcutablePath Uses

func GetExcutablePath() string

GetExcutablePath returns the executable file path

func GetExecutableDir Uses

func GetExecutableDir() string

GetExecutableDir returns the executable file directory

func GetFloat32 Uses

func GetFloat32(key string) float32

GetFloat32 returns the float32 value of an `Option` key.

func GetFloat32Ex Uses

func GetFloat32Ex(key string, defaultVal float32) float32

GetFloat32Ex returns the float32 value of an `Option` key.

func GetFloat32ExP Uses

func GetFloat32ExP(prefix, key string, defaultVal float32) float32

GetFloat32ExP returns the float32 value of an `Option` key.

func GetFloat32ExR Uses

func GetFloat32ExR(key string, defaultVal float32) float32

GetFloat32ExR returns the float32 value of an `Option` key with [WrapWithRxxtPrefix].

func GetFloat32ExRP Uses

func GetFloat32ExRP(prefix, key string, defaultVal float32) float32

GetFloat32ExRP returns the float32 value of an `Option` key with [WrapWithRxxtPrefix].

func GetFloat32P Uses

func GetFloat32P(prefix, key string) float32

GetFloat32P returns the float32 value of an `Option` key.

func GetFloat32R Uses

func GetFloat32R(key string) float32

GetFloat32R returns the float32 value of an `Option` key with [WrapWithRxxtPrefix].

func GetFloat32RP Uses

func GetFloat32RP(prefix, key string) float32

GetFloat32RP returns the float32 value of an `Option` key with [WrapWithRxxtPrefix].

func GetFloat64 Uses

func GetFloat64(key string) float64

GetFloat64 returns the float64 value of an `Option` key.

func GetFloat64Ex Uses

func GetFloat64Ex(key string, defaultVal float64) float64

GetFloat64Ex returns the float64 value of an `Option` key.

func GetFloat64ExP Uses

func GetFloat64ExP(prefix, key string, defaultVal float64) float64

GetFloat64ExP returns the float64 value of an `Option` key.

func GetFloat64ExR Uses

func GetFloat64ExR(key string, defaultVal float64) float64

GetFloat64ExR returns the float64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetFloat64ExRP Uses

func GetFloat64ExRP(prefix, key string, defaultVal float64) float64

GetFloat64ExRP returns the float64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetFloat64P Uses

func GetFloat64P(prefix, key string) float64

GetFloat64P returns the float64 value of an `Option` key.

func GetFloat64R Uses

func GetFloat64R(key string) float64

GetFloat64R returns the float64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetFloat64RP Uses

func GetFloat64RP(prefix, key string) float64

GetFloat64RP returns the float64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetHierarchyList Uses

func GetHierarchyList() map[string]interface{}

GetHierarchyList returns the hierarchy data

func GetInt Uses

func GetInt(key string) int

GetInt returns the int value of an `Option` key.

func GetInt64 Uses

func GetInt64(key string) int64

GetInt64 returns the int64 value of an `Option` key.

func GetInt64Ex Uses

func GetInt64Ex(key string, defaultVal int64) int64

GetInt64Ex returns the int64 value of an `Option` key.

func GetInt64ExP Uses

func GetInt64ExP(prefix, key string, defaultVal int64) int64

GetInt64ExP returns the int64 value of an `Option` key.

func GetInt64ExR Uses

func GetInt64ExR(key string, defaultVal int64) int64

GetInt64ExR returns the int64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetInt64ExRP Uses

func GetInt64ExRP(prefix, key string, defaultVal int64) int64

GetInt64ExRP returns the int64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetInt64P Uses

func GetInt64P(prefix, key string) int64

GetInt64P returns the int64 value of an `Option` key.

func GetInt64R Uses

func GetInt64R(key string) int64

GetInt64R returns the int64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetInt64RP Uses

func GetInt64RP(prefix, key string) int64

GetInt64RP returns the int64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetInt64Slice Uses

func GetInt64Slice(key string, defaultVal ...int64) []int64

GetInt64Slice returns the int slice value of an `Option` key.

func GetInt64SliceP Uses

func GetInt64SliceP(prefix, key string, defaultVal ...int64) []int64

GetInt64SliceP returns the int slice value of an `Option` key.

func GetInt64SliceR Uses

func GetInt64SliceR(key string, defaultVal ...int64) []int64

GetInt64SliceR returns the int slice value of an `Option` key with [WrapWithRxxtPrefix].

func GetInt64SliceRP Uses

func GetInt64SliceRP(prefix, key string, defaultVal ...int64) []int64

GetInt64SliceRP returns the int slice value of an `Option` key with [WrapWithRxxtPrefix].

func GetIntEx Uses

func GetIntEx(key string, defaultVal int) int

GetIntEx returns the int value of an `Option` key.

func GetIntExP Uses

func GetIntExP(prefix, key string, defaultVal int) int

GetIntExP returns the int value of an `Option` key.

func GetIntExR Uses

func GetIntExR(key string, defaultVal int) int

GetIntExR returns the int value of an `Option` key with [WrapWithRxxtPrefix].

func GetIntExRP Uses

func GetIntExRP(prefix, key string, defaultVal int) int

GetIntExRP returns the int value of an `Option` key with [WrapWithRxxtPrefix].

func GetIntP Uses

func GetIntP(prefix, key string) int

GetIntP returns the int value of an `Option` key.

func GetIntR Uses

func GetIntR(key string) int

GetIntR returns the int value of an `Option` key with [WrapWithRxxtPrefix].

func GetIntRP Uses

func GetIntRP(prefix, key string) int

GetIntRP returns the int value of an `Option` key with [WrapWithRxxtPrefix].

func GetIntSlice Uses

func GetIntSlice(key string, defaultVal ...int) []int

GetIntSlice returns the int slice value of an `Option` key.

func GetIntSliceP Uses

func GetIntSliceP(prefix, key string, defaultVal ...int) []int

GetIntSliceP returns the int slice value of an `Option` key.

func GetIntSliceR Uses

func GetIntSliceR(key string, defaultVal ...int) []int

GetIntSliceR returns the int slice value of an `Option` key with [WrapWithRxxtPrefix].

func GetIntSliceRP Uses

func GetIntSliceRP(prefix, key string, defaultVal ...int) []int

GetIntSliceRP returns the int slice value of an `Option` key with [WrapWithRxxtPrefix].

func GetMap Uses

func GetMap(key string) map[string]interface{}

GetMap an `Option` by key string, it returns a hierarchy map or nil

func GetMapR Uses

func GetMapR(key string) map[string]interface{}

GetMapR an `Option` by key string with [WrapWithRxxtPrefix], it returns a hierarchy map or nil

func GetNoColorMode Uses

func GetNoColorMode() bool

GetNoColorMode return the flag value of `--no-color`

func GetPredefinedLocations Uses

func GetPredefinedLocations() []string

GetPredefinedLocations return the searching locations for loading config files.

func GetQuietMode Uses

func GetQuietMode() bool

GetQuietMode returns the flag value of `--quiet`/`-q`

func GetR Uses

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 Uses

func GetSectionFrom(sectionKeyPath string, holder interface{}) (err error)

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 Uses

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 GetString Uses

func GetString(key string) string

GetString returns the string value of an `Option` key.

func GetStringEx Uses

func GetStringEx(key, defaultVal string) string

GetString returns the string value of an `Option` key.

func GetStringExP Uses

func GetStringExP(prefix, key, defaultVal string) string

GetStringExP returns the string value of an `Option` key.

func GetStringExR Uses

func GetStringExR(key, defaultVal string) string

GetStringExR returns the string value of an `Option` key with [WrapWithRxxtPrefix].

func GetStringExRP Uses

func GetStringExRP(prefix, key, defaultVal string) string

GetStringExRP returns the string value of an `Option` key with [WrapWithRxxtPrefix].

func GetStringP Uses

func GetStringP(prefix, key string) string

GetStringP returns the string value of an `Option` key.

func GetStringR Uses

func GetStringR(key string) string

GetStringR returns the string value of an `Option` key with [WrapWithRxxtPrefix].

func GetStringRP Uses

func GetStringRP(prefix, key string) string

GetStringRP returns the string value of an `Option` key with [WrapWithRxxtPrefix].

func GetStringSlice Uses

func GetStringSlice(key string, defaultVal ...string) []string

GetStringSlice returns the string slice value of an `Option` key.

func GetStringSliceP Uses

func GetStringSliceP(prefix, key string, defaultVal ...string) []string

GetStringSliceP returns the string slice value of an `Option` key.

func GetStringSliceR Uses

func GetStringSliceR(key string, defaultVal ...string) []string

GetStringSliceR returns the string slice value of an `Option` key with [WrapWithRxxtPrefix].

func GetStringSliceRP Uses

func GetStringSliceRP(prefix, key string, defaultVal ...string) []string

GetStringSliceRP returns the string slice value of an `Option` key with [WrapWithRxxtPrefix].

func GetUint Uses

func GetUint(key string) uint

GetUint returns the uint value of an `Option` key.

func GetUint64 Uses

func GetUint64(key string) uint64

GetUint64 returns the uint64 value of an `Option` key.

func GetUint64Ex Uses

func GetUint64Ex(key string, defaultVal uint64) uint64

GetUint64Ex returns the uint64 value of an `Option` key.

func GetUint64ExP Uses

func GetUint64ExP(prefix, key string, defaultVal uint64) uint64

GetUint64ExP returns the uint64 value of an `Option` key.

func GetUint64ExR Uses

func GetUint64ExR(key string, defaultVal uint64) uint64

GetUint64ExR returns the uint64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetUint64ExRP Uses

func GetUint64ExRP(prefix, key string, defaultVal uint64) uint64

GetUint64ExRP returns the uint64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetUint64P Uses

func GetUint64P(prefix, key string) uint64

GetUint64P returns the uint64 value of an `Option` key.

func GetUint64R Uses

func GetUint64R(key string) uint64

GetUint64R returns the uint64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetUint64RP Uses

func GetUint64RP(prefix, key string) uint64

GetUint64RP returns the uint64 value of an `Option` key with [WrapWithRxxtPrefix].

func GetUint64Slice Uses

func GetUint64Slice(key string, defaultVal ...uint64) []uint64

GetUint64Slice returns the int slice value of an `Option` key.

func GetUint64SliceP Uses

func GetUint64SliceP(prefix, key string, defaultVal ...uint64) []uint64

GetUint64SliceP returns the int slice value of an `Option` key.

func GetUint64SliceR Uses

func GetUint64SliceR(key string, defaultVal ...uint64) []uint64

GetUint64SliceR returns the int slice value of an `Option` key with [WrapWithRxxtPrefix].

func GetUint64SliceRP Uses

func GetUint64SliceRP(prefix, key string, defaultVal ...uint64) []uint64

GetUint64SliceRP returns the int slice value of an `Option` key with [WrapWithRxxtPrefix].

func GetUintEx Uses

func GetUintEx(key string, defaultVal uint) uint

GetUintEx returns the uint value of an `Option` key.

func GetUintExP Uses

func GetUintExP(prefix, key string, defaultVal uint) uint

GetUintExP returns the uint value of an `Option` key.

func GetUintExR Uses

func GetUintExR(key string, defaultVal uint) uint

GetUintExR returns the uint value of an `Option` key with [WrapWithRxxtPrefix].

func GetUintExRP Uses

func GetUintExRP(prefix, key string, defaultVal uint) uint

GetUintExRP returns the uint value of an `Option` key with [WrapWithRxxtPrefix].

func GetUintP Uses

func GetUintP(prefix, key string) uint

GetUintP returns the uint value of an `Option` key.

func GetUintR Uses

func GetUintR(key string) uint

GetUintR returns the uint value of an `Option` key with [WrapWithRxxtPrefix].

func GetUintRP Uses

func GetUintRP(prefix, key string) uint

GetUintRP returns the uint value of an `Option` key with [WrapWithRxxtPrefix].

func GetUsedConfigFile Uses

func GetUsedConfigFile() string

GetUsedConfigFile returns the main config filename (generally it's `<appname>.yml`)

func GetUsedConfigSubDir Uses

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 Uses

func GetVerboseMode() bool

GetVerboseMode returns the flag value of `--verbose`/`-v`

func InTesting Uses

func InTesting() bool

InTesting detects whether is running under go test mode

func IsDigitHeavy Uses

func IsDigitHeavy(s string) bool

IsDigitHeavy tests if the whole string is digit

func IsDirectory Uses

func IsDirectory(path string) (bool, error)

IsDirectory tests whether `path` is a directory or not

func IsRegularFile Uses

func IsRegularFile(path string) (bool, error)

IsRegularFile tests whether `path` is a normal regular file or not

func Launch Uses

func Launch(cmd string, args ...string) (err error)

Launch executes a command setting both standard input, output and error.

func LaunchEditor Uses

func LaunchEditor(editor string) (content []byte, err error)

LaunchEditor launches the specified editor

func LaunchEditorWith Uses

func LaunchEditorWith(editor string, filename string) (content []byte, err error)

LaunchEditorWith launches the specified editor with a filename

func LoadConfigFile Uses

func LoadConfigFile(file string) (err error)

LoadConfigFile loads a yaml config file and merge the settings into `rxxtOptions` and load files in the `conf.d` child directory too.

func MergeWith Uses

func MergeWith(m map[string]interface{}) (err error)

MergeWith will merge a map recursive. You could merge a yaml/json/toml options into cmdr Hierarchy Options.

func NormalizeDir Uses

func NormalizeDir(s string) string

NormalizeDir make dir name normalized

func RemoveDirRecursive Uses

func RemoveDirRecursive(dir string) (err error)

RemoveDirRecursive removes a directory and any children it contains.

func RemoveOnConfigLoadedListener Uses

func RemoveOnConfigLoadedListener(c ConfigReloaded)

RemoveOnConfigLoadedListener remove an functor on config loaded and merged

func ResetOptions Uses

func ResetOptions()

ResetOptions to reset the exists `Options`, so that you could follow a `LoadConfigFile()` with it.

func SaveAsJSON Uses

func SaveAsJSON(filename string) (err error)

SaveAsJSON to Save all config entries as a json file

func SaveAsToml Uses

func SaveAsToml(filename string) (err error)

SaveAsToml to Save all config entries as a toml file

func SaveAsYaml Uses

func SaveAsYaml(filename string) (err error)

SaveAsYaml to Save all config entries as a yaml file

func SaveObjAsToml Uses

func SaveObjAsToml(obj interface{}, filename string) (err error)

SaveObjAsToml to Save an object as a toml file

func Set Uses

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 SetNx Uses

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 Uses

func SetOnConfigLoadedListener(c ConfigReloaded, enabled bool)

SetOnConfigLoadedListener enable/disable an functor on config loaded and merged

func Soundex Uses

func Soundex(s string) (snd4 string)

Soundex returns the english word's soundex value, such as: 'tags' => 't322'

func StripOrderPrefix Uses

func StripOrderPrefix(s string) string

StripOrderPrefix strips the prefix string fragment for sorting order. see also: Command.Group, Flag.Group, ...

func TrapSignals Uses

func TrapSignals(onTrapped func(s os.Signal), signals ...os.Signal) (waiter func())

TrapSignals is a helper for simplify your infinite loop codes.

Usage

 func enteringLoop() {
	  waiter := cmdr.TrapSignals(func(s os.Signal) {
	    logrus.Debugf("receive signal '%v' in onTrapped()", s)
	  })
	  go waiter()
 }

func WalkAllCommands Uses

func WalkAllCommands(walk func(cmd *Command, index int) (err error)) (err error)

WalkAllCommands loops for all commands, starting from root.

func WrapWithRxxtPrefix Uses

func WrapWithRxxtPrefix(key string) string

WrapWithRxxtPrefix wrap an key with [RxxtPrefix], for [GetXxx(key)] and [GetXxxP(prefix,key)]

type BaseOpt Uses

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 Uses

func (s *BaseOpt) GetLongTitleNamesArray() []string

GetLongTitleNamesArray returns long name and aliases as an array

func (*BaseOpt) GetShortTitleNamesArray Uses

func (s *BaseOpt) GetShortTitleNamesArray() []string

GetShortTitleNamesArray returns short name as an array

func (*BaseOpt) GetTitleName Uses

func (s *BaseOpt) GetTitleName() string

GetTitleName returns name/full/short string

func (*BaseOpt) GetTitleNames Uses

func (s *BaseOpt) GetTitleNames() string

GetTitleNames return the joint string of short,full,aliases names

func (*BaseOpt) GetTitleNamesArray Uses

func (s *BaseOpt) GetTitleNamesArray() []string

GetTitleNamesArray returns short,full,aliases names

func (*BaseOpt) GetTitleNamesBy Uses

func (s *BaseOpt) GetTitleNamesBy(delimChar string) string

GetTitleNamesBy returns the joint string of short,full,aliases names

func (*BaseOpt) HasParent Uses

func (s *BaseOpt) HasParent() bool

HasParent detects whether owner is available or not

type Command Uses

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 Uses

func FindSubCommand(longName string, cmd *Command) (res *Command)

FindSubCommand find sub-command with `longName` from `cmd` if cmd == nil: finding from root command

func FindSubCommandRecursive Uses

func FindSubCommandRecursive(longName string, cmd *Command) (res *Command)

FindSubCommandRecursive find sub-command with `longName` from `cmd` recursively if cmd == nil: finding from root command

func (*Command) FindFlag Uses

func (c *Command) FindFlag(longName string) (res *Flag)

FindFlag find flag with `longName` from `cmd`

func (*Command) FindFlagRecursive Uses

func (c *Command) FindFlagRecursive(longName string) (res *Flag)

FindFlagRecursive find flag with `longName` from `cmd` recursively

func (*Command) FindSubCommand Uses

func (c *Command) FindSubCommand(longName string) (res *Command)

FindSubCommand find sub-command with `longName` from `cmd`

func (*Command) FindSubCommandRecursive Uses

func (c *Command) FindSubCommandRecursive(longName string) (res *Command)

FindSubCommandRecursive find sub-command with `longName` from `cmd` recursively

func (*Command) GetExpandableNames Uses

func (c *Command) GetExpandableNames() string

GetExpandableNames returns the names comma splitted string.

func (*Command) GetExpandableNamesArray Uses

func (c *Command) GetExpandableNamesArray() []string

GetExpandableNamesArray returns the names array of command, includes short name and long name.

func (*Command) GetHitStr Uses

func (c *Command) GetHitStr() string

GetHitStr returns the matched command string

func (*Command) GetName Uses

func (c *Command) GetName() string

GetName returns the name of a `Command`.

func (*Command) GetOwner Uses

func (c *Command) GetOwner() *Command

GetOwner returns the parent command object

func (*Command) GetParentName Uses

func (c *Command) GetParentName() string

GetParentName returns the owner command name

func (*Command) GetQuotedGroupName Uses

func (c *Command) GetQuotedGroupName() string

GetQuotedGroupName returns the group name quoted string.

func (*Command) GetRoot Uses

func (c *Command) GetRoot() *RootCommand

GetRoot returns the `RootCommand`

func (*Command) GetSubCommandNamesBy Uses

func (c *Command) GetSubCommandNamesBy(delimChar string) string

GetSubCommandNamesBy returns the joint string of subcommands

func (*Command) IsRoot Uses

func (c *Command) IsRoot() bool

IsRoot returns true if this command is a RootCommand

func (*Command) PrintBuildInfo Uses

func (c *Command) PrintBuildInfo()

PrintBuildInfo print building information

func (*Command) PrintHelp Uses

func (c *Command) PrintHelp(justFlags bool)

PrintHelp prints help screen

func (*Command) PrintVersion Uses

func (c *Command) PrintVersion()

PrintVersion prints versions information

type ConfigReloaded Uses

type ConfigReloaded interface {
    OnConfigReloaded()
}

ConfigReloaded for config reloaded

type Copier Uses

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 Uses

type DistanceOption func(StringDistance)

DistanceOption is a functional options prototype

func JWWithThreshold Uses

func JWWithThreshold(threshold float64) DistanceOption

JWWithThreshold sets the threshold for Jaro-Winkler algorithm.

type ErrorForCmdr Uses

type ErrorForCmdr struct {
    Inner     error
    Ignorable bool
    Msg       string
}

ErrorForCmdr structure

func NewError Uses

func NewError(ignorable bool, inner error, args ...interface{}) *ErrorForCmdr

NewError formats a ErrorForCmdr object

func NewErrorWithMsg Uses

func NewErrorWithMsg(msg string, inner error) *ErrorForCmdr

NewErrorWithMsg formats a ErrorForCmdr object

func (*ErrorForCmdr) Error Uses

func (s *ErrorForCmdr) Error() string

type ExecOption Uses

type ExecOption func(w *ExecWorker)

ExecOption is the functional option for Exec()

func WithAfterArgsParsed Uses

func WithAfterArgsParsed(hookFunc func(cmd *Command, args []string) (err error)) ExecOption

WithAfterArgsParsed sets a callback point after command-line args parsed by cmdr internal exec(). Your callback func will be invoked before invoking the matched command `cmd`. At this time, all command-line args parsed and a command found.

If program was launched with empty or wrong arguments, your callback func won't triggered.

When empty argument or `--help` found, cmdr will display help screen. To customize it see also cmdr.WithCustomShowVersion and cmdr.WithCustomShowBuildInfo.

When any wrong/warn arguments found, cmdr will display some tip message. To customize it see also cmdr.WithUnknownOptionHandler.

func WithAutomaticEnvHooks Uses

func WithAutomaticEnvHooks(hook HookOptsFunc) ExecOption

WithAutomaticEnvHooks sets the hook after building automatic environment.

func WithBuiltinCommands Uses

func WithBuiltinCommands(versionsCmds, helpCmds, verboseCmds, generateCmds, generalCmdrCmds bool) ExecOption

WithBuiltinCommands enables/disables those builtin predefined commands. Such as:

- versionsCmds / EnableVersionCommands supports injecting the default `--version` flags and commands
- helpCmds / EnableHelpCommands supports injecting the default `--help` flags and commands
- verboseCmds / EnableVerboseCommands supports injecting the default `--verbose` flags and commands
- generalCmdrCmds / EnableCmdrCommands support these flags: `--strict-mode`, `--no-env-overrides`, and `--no-color`
- generateCmds / EnableGenerateCommands supports injecting the default `generate` commands and sub-commands

func WithConfigLoadedListener Uses

func WithConfigLoadedListener(c ConfigReloaded) ExecOption

WithConfigLoadedListener add an functor on config loaded and merged

func WithCustomShowBuildInfo Uses

func WithCustomShowBuildInfo(fn func()) ExecOption

WithCustomShowBuildInfo supports your `ShowBuildInfo()` instead of internal `showBuildInfo()`

func WithCustomShowVersion Uses

func WithCustomShowVersion(fn func()) ExecOption

WithCustomShowVersion supports your `ShowVersion()` instead of internal `showVersion()`

func WithEnvPrefix Uses

func WithEnvPrefix(prefix ...string) ExecOption

WithEnvPrefix sets the environment variable text prefixes. cmdr will lookup envvars for a key.

func WithHelpPainter Uses

func WithHelpPainter(painter Painter) ExecOption

WithHelpPainter allows to change the behavior and facade of help screen.

func WithHelpTabStop Uses

func WithHelpTabStop(tabStop int) ExecOption

WithHelpTabStop sets the tab-stop position in the help screen

func WithIgnoreWrongEnumValue Uses

func WithIgnoreWrongEnumValue(ignored bool) ExecOption

WithIgnoreWrongEnumValue will be put into `cmdrError.Ignorable` while wrong enumerable value found in parsing command-line options. The default is true.

Main program might decide whether it's a warning or error.

See also

[Flag.ValidArgs]

func WithInternalOutputStreams Uses

func WithInternalOutputStreams(out, err *bufio.Writer) ExecOption

WithInternalOutputStreams sets the internal output streams for debugging

func WithLogex Uses

func WithLogex() ExecOption

WithLogex enables logex integration

func WithNoColor Uses

func WithNoColor(b bool) ExecOption

WithNoColor make console outputs plain and without ANSI escape colors

Since v1.6.2+

func WithNoDefaultHelpScreen Uses

func WithNoDefaultHelpScreen(b bool) ExecOption

WithNoDefaultHelpScreen true to disable printing help screen if without any arguments

func WithNoEnvOverrides Uses

func WithNoEnvOverrides(b bool) ExecOption

WithNoEnvOverrides enables the internal no-env-overrides mode

Since v1.6.2+

In this mode, cmdr do NOT find and transfer equivalent envvar value into cmdr options store.

func WithNoLoadConfigFiles Uses

func WithNoLoadConfigFiles(b bool) ExecOption

WithNoLoadConfigFiles true means no loading config files

func WithOptionsPrefix Uses

func WithOptionsPrefix(prefix ...string) ExecOption

WithOptionsPrefix create a top-level namespace, which contains all normalized `Flag`s. =WithRxxtPrefix

func WithPredefinedLocations Uses

func WithPredefinedLocations(locations ...string) ExecOption

WithPredefinedLocations sets the environment variable text prefixes. cmdr will lookup envvars for a key.

func WithRxxtPrefix Uses

func WithRxxtPrefix(prefix ...string) ExecOption

WithRxxtPrefix create a top-level namespace, which contains all normalized `Flag`s. cmdr will lookup envvars for a key.

func WithSimilarThreshold Uses

func WithSimilarThreshold(similiarThreshold float64) ExecOption

WithSimilarThreshold defines a threshold for command/option similar detector. Default threshold is 0.6666666666666666. See also JaroWinklerDistance

func WithStrictMode Uses

func WithStrictMode(b bool) ExecOption

WithStrictMode enables the internal strict mode

Since v1.6.2+

In this mode, any warnings will be treat as an error and cause app fatal exit.

In normal mode, these cases are assumed as warnings: - flag name not found - command or sub-command name not found - value extracting failed - ...

func WithUnknownOptionHandler Uses

func WithUnknownOptionHandler(handler UnknownOptionHandler) ExecOption

WithUnknownOptionHandler enables your customized wrong command/flag processor. internal processor supports smart suggestions for those wrong commands and flags.

func WithXrefBuildingHooks Uses

func WithXrefBuildingHooks(beforeXrefBuildingX, afterXrefBuiltX HookFunc) ExecOption

WithXrefBuildingHooks sets the hook before and after building xref indices. It's replacers for AddOnBeforeXrefBuilding, and AddOnAfterXrefBuilt.

type ExecWorker Uses

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

ExecWorker is a core logic worker and holder

func InternalResetWorker Uses

func InternalResetWorker() (w *ExecWorker)

InternalResetWorker is an internal helper, esp for debugging

func (*ExecWorker) AddOnAfterXrefBuilt Uses

func (w *ExecWorker) AddOnAfterXrefBuilt(cb HookFunc)

AddOnAfterXrefBuilt add hook func daemon plugin needed

func (*ExecWorker) AddOnBeforeXrefBuilding Uses

func (w *ExecWorker) AddOnBeforeXrefBuilding(cb HookFunc)

AddOnBeforeXrefBuilding add hook func daemon plugin needed

func (*ExecWorker) InternalExecFor Uses

func (w *ExecWorker) InternalExecFor(rootCmd *RootCommand, args []string) (err error)

InternalExecFor is an internal helper, esp for debugging

type Flag Uses

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
    // contains filtered or unexported fields
}

Flag means a flag, a option, or a opt.

func FindFlag Uses

func FindFlag(longName string, cmd *Command) (res *Flag)

FindFlag find flag with `longName` from `cmd` if cmd == nil: finding from root command

func FindFlagRecursive Uses

func FindFlagRecursive(longName string, cmd *Command) (res *Flag)

FindFlagRecursive find flag with `longName` from `cmd` recursively if cmd == nil: finding from root command

func (*Flag) GetDescZsh Uses

func (s *Flag) GetDescZsh() (desc string)

GetDescZsh temp

func (*Flag) GetTitleFlagNames Uses

func (s *Flag) GetTitleFlagNames() string

GetTitleFlagNames temp

func (*Flag) GetTitleFlagNamesBy Uses

func (s *Flag) GetTitleFlagNamesBy(delimChar string) string

GetTitleFlagNamesBy temp

func (*Flag) GetTitleFlagNamesByMax Uses

func (s *Flag) GetTitleFlagNamesByMax(delimChar string, maxCount int) string

GetTitleFlagNamesByMax temp

func (*Flag) GetTitleZshFlagName Uses

func (s *Flag) GetTitleZshFlagName() (str string)

GetTitleZshFlagName temp

func (*Flag) GetTitleZshFlagNames Uses

func (s *Flag) GetTitleZshFlagNames(delimChar string) (str string)

GetTitleZshFlagNames temp

func (*Flag) GetTitleZshFlagNamesArray Uses

func (s *Flag) GetTitleZshFlagNamesArray() (ary []string)

GetTitleZshFlagNamesArray temp

func (*Flag) GetTriggeredTimes Uses

func (s *Flag) GetTriggeredTimes() int

GetTriggeredTimes returns the matched times

type HookFunc Uses

type HookFunc func(root *RootCommand, args []string)

HookFunc the hook function prototype for SetBeforeXrefBuilding and SetAfterXrefBuilt

type HookOptsFunc Uses

type HookOptsFunc func(root *RootCommand, opts *Options)

HookOptsFunc the hook function prototype

type OptCmd Uses

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 NewCmd Uses

func NewCmd() (opt OptCmd)

NewCmd for fluent api

func NewCmdFrom Uses

func NewCmdFrom(cmd *Command) (opt OptCmd)

NewCmdFrom for fluent api

func NewSubCmd Uses

func NewSubCmd() (opt OptCmd)

NewSubCmd for fluent api

type OptFlag Uses

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 NewBool Uses

func NewBool() (opt OptFlag)

NewBool for fluent api

func NewDuration Uses

func NewDuration() (opt OptFlag)

NewDuration for fluent api

func NewDurationFrom Uses

func NewDurationFrom(flg *Flag) (opt OptFlag)

NewDurationFrom for fluent api

func NewFloat32 Uses

func NewFloat32() (opt OptFlag)

NewFloat32 for fluent api

func NewFloat64 Uses

func NewFloat64() (opt OptFlag)

NewFloat64 for fluent api

func NewInt Uses

func NewInt() (opt OptFlag)

NewInt for fluent api

func NewInt64 Uses

func NewInt64() (opt OptFlag)

NewInt64 for fluent api

func NewIntSlice Uses

func NewIntSlice() (opt OptFlag)

NewIntSlice for fluent api

func NewString Uses

func NewString() (opt OptFlag)

NewString for fluent api

func NewStringSlice Uses

func NewStringSlice() (opt OptFlag)

NewStringSlice for fluent api

func NewUint Uses

func NewUint() (opt OptFlag)

NewUint for fluent api

func NewUint64 Uses

func NewUint64() (opt OptFlag)

NewUint64 for fluent api

type OptFlagType Uses

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 Uses

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

Options is a holder of all options

func GetOptions Uses

func GetOptions() *Options

GetOptions returns the global options instance (rxxtOptions), ie. cmdr Options Store

func NewOptions Uses

func NewOptions() *Options

NewOptions returns an `Options` structure pointer

func NewOptionsWith Uses

func NewOptionsWith(entries map[string]interface{}) *Options

NewOptionsWith returns an `Options` structure pointer

func (*Options) DumpAsString Uses

func (s *Options) DumpAsString() (str string)

DumpAsString for debugging.

func (*Options) Get Uses

func (s *Options) Get(key string) interface{}

Get an `Option` by key string, eg: “`golang cmdr.Get("app.logger.level") => 'DEBUG',... “`

func (*Options) GetBoolEx Uses

func (s *Options) GetBoolEx(key string, defaultVal bool) (ret bool)

GetBoolEx returns the bool value of an `Option` key.

func (*Options) GetDuration Uses

func (s *Options) GetDuration(key string, defaultVal time.Duration) (ir time.Duration)

GetDuration returns the time duration value of an `Option` key.

func (*Options) GetFloat32Ex Uses

func (s *Options) GetFloat32Ex(key string, defaultVal float32) (ir float32)

GetFloat32Ex returns the float32 value of an `Option` key.

func (*Options) GetFloat64Ex Uses

func (s *Options) GetFloat64Ex(key string, defaultVal float64) (ir float64)

GetFloat64Ex returns the float64 value of an `Option` key.

func (*Options) GetHierarchyList Uses

func (s *Options) GetHierarchyList() map[string]interface{}

GetHierarchyList returns the hierarchy data for dumping

func (*Options) GetInt64Slice Uses

func (s *Options) GetInt64Slice(key string, defaultVal ...int64) (ir []int64)

GetInt64Slice returns the string slice value of an `Option` key.

func (*Options) GetIntEx Uses

func (s *Options) GetIntEx(key string, defaultVal int64) (ir int64)

GetIntEx returns the int64 value of an `Option` key.

func (*Options) GetIntSlice Uses

func (s *Options) GetIntSlice(key string, defaultVal ...int) (ir []int)

GetIntSlice returns the string slice value of an `Option` key.

func (*Options) GetMap Uses

func (s *Options) GetMap(key string) map[string]interface{}

GetMap an `Option` by key string, it returns a hierarchy map or nil

func (*Options) GetString Uses

func (s *Options) GetString(key, defaultVal string) (ret string)

GetString returns the string value of an `Option` key.

func (*Options) GetStringSlice Uses

func (s *Options) GetStringSlice(key string, defaultVal ...string) (ir []string)

GetStringSlice returns the string slice value of an `Option` key.

func (*Options) GetUint64Slice Uses

func (s *Options) GetUint64Slice(key string, defaultVal ...uint64) (ir []uint64)

GetUint64Slice returns the string slice value of an `Option` key.

func (*Options) GetUintEx Uses

func (s *Options) GetUintEx(key string, defaultVal uint64) (ir uint64)

GetUintEx returns the uint64 value of an `Option` key.

func (*Options) LoadConfigFile Uses

func (s *Options) LoadConfigFile(file string) (err error)

LoadConfigFile loads a yaml config file and merge the settings into `rxxtOptions` and load files in the `conf.d` child directory too.

func (*Options) MergeWith Uses

func (s *Options) MergeWith(m map[string]interface{}) (err error)

MergeWith will merge a map recursive.

func (*Options) Reset Uses

func (s *Options) Reset()

Reset the exists `Options`, so that you could follow a `LoadConfigFile()` with it.

func (*Options) Set Uses

func (s *Options) Set(key string, val interface{})

Set set the value of an `Option` key. The key MUST not have an `app` prefix. eg: “`golang cmdr.Set("debug", true) cmdr.GetBool("app.debug") => true “`

func (*Options) SetNx Uses

func (s *Options) 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).

type Painter Uses

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 Uses

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

RootCmdOpt for fluent api

func Root Uses

func Root(appName, version string) (opt *RootCmdOpt)

Root for fluent api, to create a new [*RootCmdOpt] object.

func RootFrom Uses

func RootFrom(root *RootCommand) (opt *RootCmdOpt)

RootFrom for fluent api, to create the new [*RootCmdOpt] object from an existed [RootCommand]

func (*RootCmdOpt) Action Uses

func (s *RootCmdOpt) Action(action func(cmd *Command, args []string) (err error)) (opt OptCmd)

func (*RootCmdOpt) Aliases Uses

func (s *RootCmdOpt) Aliases(aliases ...string) (opt OptCmd)

func (*RootCmdOpt) Bool Uses

func (s *RootCmdOpt) Bool() (opt OptFlag)

func (*RootCmdOpt) Copyright Uses

func (s *RootCmdOpt) Copyright(copyright, author string) *RootCmdOpt

Copyright for fluent api

func (*RootCmdOpt) Deprecated Uses

func (s *RootCmdOpt) Deprecated(deprecation string) (opt OptCmd)

func (*RootCmdOpt) Description Uses

func (s *RootCmdOpt) Description(oneLine, long string) (opt OptCmd)

func (*RootCmdOpt) Duration Uses

func (s *RootCmdOpt) Duration() (opt OptFlag)

func (*RootCmdOpt) Examples Uses

func (s *RootCmdOpt) Examples(examples string) (opt OptCmd)

func (*RootCmdOpt) Float32 Uses

func (s *RootCmdOpt) Float32() (opt OptFlag)

func (*RootCmdOpt) Float64 Uses

func (s *RootCmdOpt) Float64() (opt OptFlag)

func (*RootCmdOpt) Group Uses

func (s *RootCmdOpt) Group(group string) (opt OptCmd)

func (*RootCmdOpt) Header Uses

func (s *RootCmdOpt) Header(header string) *RootCmdOpt

Header for fluent api

func (*RootCmdOpt) Hidden Uses

func (s *RootCmdOpt) Hidden(hidden bool) (opt OptCmd)

func (*RootCmdOpt) Int Uses

func (s *RootCmdOpt) Int() (opt OptFlag)

func (*RootCmdOpt) Int64 Uses

func (s *RootCmdOpt) Int64() (opt OptFlag)

func (*RootCmdOpt) IntSlice Uses

func (s *RootCmdOpt) IntSlice() (opt OptFlag)

func (*RootCmdOpt) Long Uses

func (s *RootCmdOpt) Long(long string) (opt OptCmd)

func (*RootCmdOpt) NewFlag Uses

func (s *RootCmdOpt) NewFlag(typ OptFlagType) (opt OptFlag)

func (*RootCmdOpt) NewSubCommand Uses

func (s *RootCmdOpt) NewSubCommand() (opt OptCmd)

func (*RootCmdOpt) OwnerCommand Uses

func (s *RootCmdOpt) OwnerCommand() (opt OptCmd)

func (*RootCmdOpt) PostAction Uses

func (s *RootCmdOpt) PostAction(pre func(cmd *Command, args []string)) (opt OptCmd)

func (*RootCmdOpt) PreAction Uses

func (s *RootCmdOpt) PreAction(pre func(cmd *Command, args []string) (err error)) (opt OptCmd)

func (*RootCmdOpt) RootCommand Uses

func (s *RootCmdOpt) RootCommand() (root *RootCommand)

func (*RootCmdOpt) SetOwner Uses

func (s *RootCmdOpt) SetOwner(opt OptCmd)

func (*RootCmdOpt) Short Uses

func (s *RootCmdOpt) Short(short string) (opt OptCmd)

func (*RootCmdOpt) String Uses

func (s *RootCmdOpt) String() (opt OptFlag)

func (*RootCmdOpt) StringSlice Uses

func (s *RootCmdOpt) StringSlice() (opt OptFlag)

func (*RootCmdOpt) TailPlaceholder Uses

func (s *RootCmdOpt) TailPlaceholder(placeholder string) (opt OptCmd)

func (*RootCmdOpt) Titles Uses

func (s *RootCmdOpt) Titles(short, long string, aliases ...string) (opt OptCmd)

func (*RootCmdOpt) Uint Uses

func (s *RootCmdOpt) Uint() (opt OptFlag)

func (*RootCmdOpt) Uint64 Uses

func (s *RootCmdOpt) Uint64() (opt OptFlag)

type RootCommand Uses

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 Uses

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 Uses

func JaroWinklerDistance(opts ...DistanceOption) StringDistance

JaroWinklerDistance returns an calculator for two strings distance metric, with Jaro-Winkler algorithm.

type UnknownOptionHandler Uses

type UnknownOptionHandler func(isFlag bool, title string, cmd *Command, args []string) (fallbackToDefaultDetector bool)

UnknownOptionHandler for WithSimilarThreshold/SetUnknownOptionHandler

Directories

PathSynopsis
conf
flag
fluent

Package cmdr imports 31 packages (graph) and is imported by 2 packages. Updated 2019-10-14. Refresh now. Tools for package owners.