cmdr

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2019 License: MIT Imports: 28 Imported by: 76

README

cmdr

Build Status GitHub tag (latest SemVer) GoDoc Go Report Card codecov Mentioned in Awesome Go

cmdr is a POSIX/GNU style, command-line UI (CLI) Go library. It is a getopt-like parser of command-line options, be compatible with the getopt_long command line UI, which is an extension of the syntax recommended by POSIX.

see also Examples, and cmdr-http2 (a http2 server with daemon supports, graceful shutdown).

Youtube - 李宗盛2013最新單曲 山丘 官方完整版音檔 / Jonathan Lee - Hill CHT + ENU

image

Import

for non-go-modules user:

import "gopkg.in/hedzr/cmdr.v1"

with go-modules enabled:

import "github.com/hedzr/cmdr"

Features

  • Unix getopt(3) representation but without its programmatic interface.

    • Options with short names (-h)
    • Options with long names (--help)
    • Options with aliases (—helpme, —usage, --info)
    • Options with and without arguments (bool v.s. other type)
    • Options with optional arguments and default values
    • Multiple option groups each containing a set of options
    • Supports multiple short options -aux
    • Supports namespaces for (nested) option groups
  • Automatic help screen generation (Generate and print well-formatted help message)

  • Support the Fluent API style

    root := cmdr.Root("aa", "1.0.1").Header("aa - test for cmdr - hedzr")
    rootCmd = root.RootCommand()
    
    co := root.NewSubCommand().
    	Titles("ms", "micro-service").
    	Description("", "").
    	Group("")
    
    co.NewFlag(cmdr.OptFlagTypeUint).
    	Titles("t", "retry").
    	Description("", "").
    	Group("").
    	DefaultValue(3, "RETRY")
    
    cTags := co.NewSubCommand().
    	Titles("t", "tags").
    	Description("", "").
    	Group("")
    
  • Muiltiple API styles:

  • Strict Mode

    • false: Ignoring unknown command line options (default)
    • true: Report error on unknown commands and options if strict mode enabled (optional) enable strict mode:
      • env var APP_STRICT_MODE=true
      • hidden option: --strict-mode (if cmdr.EnableCmdrCommands == true)
      • entry in config file:
        app:
          strict-mode: true
        
  • Support for unlimited multiple sub-commands.

  • Support -I/usr/include -I=/usr/include -I /usr/include option argument specifications Automatically allows those formats (applied to long option too):

    • -I file, -Ifile, and -I=files
    • -I 'file', -I'file', and -I='files'
    • -I "file", -I"file", and -I="files"
  • Support for -D+, -D- to enable/disable a bool option.

  • Support for PassThrough by --. (Passing remaining command line arguments after -- (optional))

  • Support for options being specified multiple times, with different values

  • Smart suggestions for wrong command and flags

  • Groupable commands and options/flags.

    Sortable group name with [0-9A-Za-z]+\..+ format, eg:

    1001.c++, 1100.golang, 1200.java, …;

    abcd.c++, b999.golang, zzzz.java, …;

  • Sortable commands and options/flags. Or sorted by alphabetic order.

  • Predefined commands and flags:

    • Help: -h, -?, --help, ...
    • Version & Build Info: --version/-V, --build-info/-#
    • Verbose & Debug: —verbose/-v, —debug/-D, —quiet/-q
    • --no-env-overrides, and --strict-mode
    • Generate Commands:
      • generate shell: —bash/—zsh(todo)/--auto
      • generate manual: man 1 ready.
      • generate doc: markdown ready.
  • Generators

    • Todo: manual generator, and markdown/docx/pdf generators.

    • Man Page generator: bin/demo generate man

    • Markdown generator: bin/demo generate [doc|mdk|markdown]

    • Bash and Zsh (not yet, todo) completion.

      bin/wget-demo generate shell --bash
      
  • Predefined external config file locations:

    • /etc/<appname>/<appname>.yml and conf.d sub-directory.

    • /usr/local/etc/<appname>/<appname>.yml and conf.d sub-directory.

    • $HOME/<appname>/<appname>.yml and conf.d sub-directory.

    • Watch conf.d directory:

      • AddOnConfigLoadedListener(c)
      • RemoveOnConfigLoadedListener(c)
      • SetOnConfigLoadedListener(c, enabled)
    • As a feature, do NOT watch the changes on <appname>.yml.

    • To customize the searching locations yourself:

      • SetPredefinedLocations(locations)

        SetPredefinedLocations([]string{"./config", "~/.config/cmdr/", "$GOPATH/running-configs/cmdr"})
        
    • on command-line:

      # version = 1: bin/demo ~~debug
      bin/demo --configci/etc/demo-yy ~~debug
      # version = 1.1
      bin/demo --config=ci/etc/demo-yy/any.yml ~~debug
      # version = 1.2
      
    • supports muiltiple file formats:

      • Yaml
      • JSON
      • TOML
    • SetNoLoadConfigFiles(bool) to disable external config file loading.

  • Overrides by environment variables.

    priority level: defaultValue -> config-file -> env-var -> command-line opts

  • Unify option value extraction:

    • cmdr.Get(key), cmdr.GetBool(key), cmdr.GetInt(key), cmdr.GetString(key), cmdr.GetStringSlice(key) and cmdr.GetIntSlice(key), cmdr.GetDuration(key) for Option value extractions.

      • bool
      • int, int64, uint, uint64, float32, float64
      • string
      • string slice
      • int slice
      • time duration
      • todo: float, time, duration, int slice, …, all primitive go types
      • map
      • struct: cmdr.GetSectionFrom(sectionKeyPath, &holderStruct)
    • cmdr.Set(key, value), cmdr.SerNx(key, value)

      • Set() set value by key without RxxtPrefix, eg: cmdr.Set("debug", true) for --debug.

      • SetNx() set value by exact key. so: cmdr.SetNx("app.debug", true) for --debug.

    • Fast Guide for Get, GetP and GetR:

      • cmdr.GetP(prefix, key), cmdr.GetBoolP(prefix, key), ….
      • cmdr.GetR(key), cmdr.GetBoolR(key), …, cmdr.GetMapR(key)
      • cmdr.GetRP(prefix, key), cmdr.GetBoolRP(prefix, key), ….

      cmdr.Get("app.server.port") == cmdr.GetP("app.server", "port") == cmdr.GetR("server.port") (if cmdr.RxxtPrefix == ["app"]); so:

      cmdr.Set("server.port", 7100)
      assert cmdr.GetR("server.port") == 7100
      assert cmdr.Get("app.server.port") == 7100
      
  • Walkable

    • Customizable Painter interface to loop each command and flag.
    • Walks for all commands with WalkAllCommands(walker).
  • Daemon (Linux Only)

    Uses daemon feature with go-daemon

    import "github.com/hedzr/cmdr/plugin/daemon"
    func main() {
    	daemon.Enable(NewDaemon())
    	if err := cmdr.Exec(rootCmd); err != nil {
    		log.Fatal("Error:", err)
    	}
    }
    func NewDaemon() daemon.Daemon {
    	return &DaemonImpl{}
    }
    

    See full codes in demo app, and cmdr-http2.

    bin/demo server [start|stop|status|restart|install|uninstall]
    

    install/uninstall sub-commands could install demo app as a systemd service.

    Just for Linux

  • ExecWith(rootCmd *RootCommand, beforeXrefBuilding_, afterXrefBuilt_ HookXrefFunc) (err error)

    AddOnBeforeXrefBuilding(cb)

    AddOnAfterXrefBuilt(cb)

  • Advanced features

    • Launch external editor by &Flag{BaseOpt:BaseOpt{},ExternalTool:cmdr.ExternalToolEditor}:

      just like git -m, try this command:

      EDITOR=nano bin/demo -m ~~debug
      

      Default is vim. And -m "something" can skip the launching.

    • ToggleGroup: make a group of flags as a radio-button group.

    • Safe password input for end-user: cmdr.ExternalToolPasswordInput

    • head-like option: treat app do sth -1973 as app do sth -a=1973, just like head -1.

      Flags: []*cmdr.Flag{
          {
              BaseOpt: cmdr.BaseOpt{
                  Short:       "h",
                  Full:        "head",
                  Description: "head -1 like",
              },
              DefaultValue: 0,
              HeadLike:     true,
          },
      },
      
    • limitation with enumerable values:

      Flags: []*cmdr.Flag{
          {
              BaseOpt: cmdr.BaseOpt{
                  Short:       "e",
                  Full:        "enum",
                  Description: "enum tests",
              },
              DefaultValue: "", // "apple",
              ValidArgs:    []string{"apple", "banana", "orange"},
          },
      },
      

      While a non-in-list value found, An error (*ErrorForCmdr) will be thrown:

      cmdr.ShouldIgnoreWrongEnumValue = true
      if err := cmdr.Exec(rootCmd); err != nil {
          if e, ok := err(*cmdr.ErrorForCmdr); ok {
              // e.Ignorable is a copy of [cmdr.ShouldIgnoreWrongEnumValue]
              if e.Ignorable {
                  logrus.Warning("Non-recognaizable value found: ", e)
                  os.Exit(0)
              }
          }
          logrus.Fatal(err)
      }
      
  • More...

Examples

  1. short
    simple codes with structured data style.
  2. demo
    normal demo with external config files.
  3. wget-demo
    partial-covered for GNU wget.
  4. fluent
    demostrates how to define your command-ui with the fluent api style.
  5. cmdr-http2
    http2 server with daemon supports, graceful shutdown

Documentation

Uses Fluent API
Expand to source codes
	root := cmdr.Root("aa", "1.0.1").Header("aa - test for cmdr - hedzr")
	rootCmd = root.RootCommand()

	co := root.NewSubCommand().
		Titles("ms", "micro-service").
		Description("", "").
		Group("")

	co.NewFlag(cmdr.OptFlagTypeUint).
		Titles("t", "retry").
		Description("", "").
		Group("").
		DefaultValue(3, "RETRY")

	cTags := co.NewSubCommand().
		Titles("t", "tags").
		Description("", "").
		Group("")

	cTags.NewFlag(cmdr.OptFlagTypeString).
		Titles("a", "addr").
		Description("", "").
		Group("").
		DefaultValue("consul.ops.local", "ADDR")

	cTags.NewSubCommand().
		Titles("ls", "list").
		Description("", "").
		Group("").
		Action(func(cmd *cmdr.Command, args []string) (err error) {
			return
		})

	cTags.NewSubCommand().
		Titles("a", "add").
		Description("", "").
		Group("").
		Action(func(cmd *cmdr.Command, args []string) (err error) {
			return
		})

Uses

Contrib

Feel free to issue me bug reports and fixes. Many thanks to all contributors.

License

MIT.

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	// AppName const
	AppName = "cmdr" // main app-name
	// Version const
	Version = "1.0.1" // version name
	// VersionInt const
	VersionInt = 0x010001 // using as
)
View Source
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

View Source
var (
	// GormDefaultCopier used for gorm
	GormDefaultCopier = &CopierImpl{true, true, true}
	// StandardCopier is a normal copier
	StandardCopier = &CopierImpl{false, false, false}
)
View Source
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
)
View Source
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 Clone added in v0.2.3

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

Clone deep copy source to target

func DumpAsString

func DumpAsString() (str string)

DumpAsString for debugging.

func EnsureDir

func EnsureDir(dir string) (err error)

EnsureDir checks and creates the directory.

func Exec

func Exec(rootCmd *RootCommand) (err error)

Exec is main entry of `cmdr`.

func ExecWith added in v0.2.11

func ExecWith(rootCmd *RootCommand, beforeXrefBuildingX, afterXrefBuiltX HookXrefFunc) (err error)

ExecWith is main entry of `cmdr`.

func FileExists

func FileExists(name string) bool

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

func GetBool(key string) bool

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

func GetBoolP(prefix, key string) bool

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

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 added in v0.2.23

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

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

func GetDuration(key string) time.Duration

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

func GetDurationP added in v0.2.19

func GetDurationP(prefix, key string) time.Duration

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

func GetDurationR added in v1.0.0

func GetDurationR(key string) time.Duration

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

func GetDurationRP added in v1.0.0

func GetDurationRP(prefix, key string) time.Duration

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

func GetFloat32(key string) float32

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

func GetFloat32P added in v1.0.1

func GetFloat32P(prefix, key string) float32

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

func GetFloat32R added in v1.0.1

func GetFloat32R(key string) float32

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

func GetFloat32RP added in v1.0.1

func GetFloat32RP(prefix, key string) float32

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

func GetFloat64 added in v1.0.1

func GetFloat64(key string) float64

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

func GetFloat64P added in v1.0.1

func GetFloat64P(prefix, key string) float64

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

func GetFloat64R added in v1.0.1

func GetFloat64R(key string) float64

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

func GetFloat64RP added in v1.0.1

func GetFloat64RP(prefix, key string) float64

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

func GetInt

func GetInt(key string) int

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

func GetInt64 added in v0.2.3

func GetInt64(key string) int64

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

func GetInt64P added in v0.2.3

func GetInt64P(prefix, key string) int64

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

func GetInt64R added in v0.2.23

func GetInt64R(key string) int64

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

func GetInt64RP added in v0.2.23

func GetInt64RP(prefix, key string) int64

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

func GetIntP added in v0.2.3

func GetIntP(prefix, key string) int

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

func GetIntR added in v0.2.23

func GetIntR(key string) int

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

func GetIntRP added in v0.2.23

func GetIntRP(prefix, key string) int

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

func GetIntSlice added in v0.2.19

func GetIntSlice(key string) []int

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

func GetIntSliceP added in v0.2.19

func GetIntSliceP(prefix, key string) []int

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

func GetIntSliceR added in v0.2.23

func GetIntSliceR(key string) []int

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

func GetIntSliceRP added in v0.2.23

func GetIntSliceRP(prefix, key string) []int

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

func GetMap added in v1.0.0

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

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

func GetMapR added in v1.0.0

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

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

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

func GetString(key string) string

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

func GetStringP added in v0.2.3

func GetStringP(prefix, key string) string

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

func GetStringR added in v0.2.23

func GetStringR(key string) string

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

func GetStringRP added in v0.2.23

func GetStringRP(prefix, key string) string

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

func GetStringSlice

func GetStringSlice(key string) []string

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

func GetStringSliceP added in v0.2.3

func GetStringSliceP(prefix, key string) []string

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

func GetStringSliceR added in v0.2.23

func GetStringSliceR(key string) []string

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

func GetStringSliceRP added in v0.2.23

func GetStringSliceRP(prefix, key string) []string

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

func GetUint added in v0.2.3

func GetUint(key string) uint

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

func GetUint64 added in v0.2.3

func GetUint64(key string) uint64

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

func GetUint64P added in v0.2.3

func GetUint64P(prefix, key string) uint64

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

func GetUint64R added in v0.2.23

func GetUint64R(key string) uint64

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

func GetUint64RP added in v0.2.23

func GetUint64RP(prefix, key string) uint64

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

func GetUintP added in v0.2.3

func GetUintP(prefix, key string) uint

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

func GetUintR added in v0.2.23

func GetUintR(key string) uint

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

func GetUintRP added in v0.2.23

func GetUintRP(prefix, key string) uint

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

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

func IsDigitHeavy(s string) bool

IsDigitHeavy tests if the whole string is digit

func IsDirectory added in v0.2.21

func IsDirectory(path string) (bool, error)

IsDirectory tests whether `path` is a directory or not

func IsRegularFile added in v0.2.21

func IsRegularFile(path string) (bool, error)

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

func Launch added in v0.2.13

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

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

func LaunchEditor added in v0.2.13

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

LaunchEditor launches the specified editor

func LaunchEditorWith added in v0.2.19

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

LaunchEditorWith launches the specified editor with a filename

func LoadConfigFile

func LoadConfigFile(file string) (err error)

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

func NormalizeDir added in v0.2.19

func NormalizeDir(s string) string

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

func SaveAsJSON(filename string) (err error)

SaveAsJSON to Save all config entries as a json file

func SaveAsToml added in v0.2.17

func SaveAsToml(filename string) (err error)

SaveAsToml to Save all config entries as a toml file

func SaveAsYaml added in v0.2.17

func SaveAsYaml(filename string) (err error)

SaveAsYaml to Save all config entries as a yaml file

func SaveObjAsToml added in v0.2.19

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

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: ```golang 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

func SetInternalOutputStreams(out, err *bufio.Writer)

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

func SetUnknownOptionHandler(handler func(isFlag bool, title string, cmd *Command, args []string))

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

func Soundex(s string) (snd4 string)

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

func StripOrderPrefix added in v0.2.9

func StripOrderPrefix(s string) string

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

func WalkAllCommands added in v0.2.9

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

WalkAllCommands loops for all commands, starting from root.

func WrapWithRxxtPrefix added in v0.2.23

func WrapWithRxxtPrefix(key string) string

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

Types

type BaseOpt

type BaseOpt struct {
	Name string
	// single char. example for flag: "a" -> "-a"
	// Short rune.
	Short string
	// word string. example for flag: "addr" -> "--addr"
	Full string
	// more synonyms
	Aliases []string
	// 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

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

GetLongTitleNamesArray returns long name and aliases as an array

func (*BaseOpt) GetShortTitleNamesArray added in v0.2.3

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

GetShortTitleNamesArray returns short name as an array

func (*BaseOpt) GetTitleName

func (s *BaseOpt) GetTitleName() string

GetTitleName returns name/full/short string

func (*BaseOpt) GetTitleNames

func (s *BaseOpt) GetTitleNames() string

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

func (*BaseOpt) GetTitleNamesArray

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

GetTitleNamesArray returns short,full,aliases names

func (*BaseOpt) GetTitleNamesBy

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

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

func (*BaseOpt) HasParent added in v0.2.9

func (s *BaseOpt) HasParent() bool

HasParent detects whether owner is available or not

type BoolOpt added in v0.2.15

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

BoolOpt for fluent api

func (*BoolOpt) Action added in v0.2.15

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

func (*BoolOpt) Aliases added in v0.2.15

func (s *BoolOpt) Aliases(aliases ...string) (opt OptFlag)

func (*BoolOpt) DefaultValue added in v0.2.15

func (s *BoolOpt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*BoolOpt) Deprecated added in v0.2.15

func (s *BoolOpt) Deprecated(deprecation string) (opt OptFlag)

func (*BoolOpt) Description added in v0.2.15

func (s *BoolOpt) Description(oneLine, long string) (opt OptFlag)

func (*BoolOpt) Examples added in v0.2.15

func (s *BoolOpt) Examples(examples string) (opt OptFlag)

func (*BoolOpt) ExternalTool added in v0.2.15

func (s *BoolOpt) ExternalTool(envKeyName string) (opt OptFlag)

func (*BoolOpt) Group added in v0.2.15

func (s *BoolOpt) Group(group string) (opt OptFlag)

func (*BoolOpt) HeadLike added in v1.0.2

func (s *BoolOpt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*BoolOpt) Hidden added in v0.2.15

func (s *BoolOpt) Hidden(hidden bool) (opt OptFlag)

func (*BoolOpt) Long added in v0.2.15

func (s *BoolOpt) Long(long string) (opt OptFlag)

func (*BoolOpt) OwnerCommand added in v0.2.15

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

func (*BoolOpt) RootCommand added in v0.2.15

func (s *BoolOpt) RootCommand() (root *RootCommand)

func (*BoolOpt) SetOwner added in v0.2.15

func (s *BoolOpt) SetOwner(opt OptCmd)

func (*BoolOpt) Short added in v0.2.15

func (s *BoolOpt) Short(short string) (opt OptFlag)

func (*BoolOpt) Titles added in v0.2.15

func (s *BoolOpt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*BoolOpt) ToggleGroup added in v0.2.15

func (s *BoolOpt) ToggleGroup(group string) (opt OptFlag)

func (*BoolOpt) ValidArgs added in v1.0.2

func (s *BoolOpt) ValidArgs(list ...string) (opt OptFlag)

type CmdOpt added in v0.2.15

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

CmdOpt for fluent api

func (*CmdOpt) Action added in v0.2.15

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

func (*CmdOpt) Aliases added in v0.2.15

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

func (*CmdOpt) Bool added in v0.2.15

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

func (*CmdOpt) Deprecated added in v0.2.15

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

func (*CmdOpt) Description added in v0.2.15

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

func (*CmdOpt) Duration added in v0.2.17

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

func (*CmdOpt) Examples added in v0.2.15

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

func (*CmdOpt) Float32 added in v1.0.1

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

func (*CmdOpt) Float64 added in v1.0.1

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

func (*CmdOpt) Group added in v0.2.15

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

func (*CmdOpt) Hidden added in v0.2.15

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

func (*CmdOpt) Int added in v0.2.15

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

func (*CmdOpt) Int64 added in v0.2.15

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

func (*CmdOpt) IntSlice added in v0.2.15

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

func (*CmdOpt) Long added in v0.2.15

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

func (*CmdOpt) NewFlag added in v0.2.15

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

func (*CmdOpt) NewSubCommand added in v0.2.15

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

func (*CmdOpt) OwnerCommand added in v0.2.15

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

func (*CmdOpt) PostAction added in v0.2.15

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

func (*CmdOpt) PreAction added in v0.2.15

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

func (*CmdOpt) RootCommand added in v0.2.15

func (s *CmdOpt) RootCommand() (root *RootCommand)

func (*CmdOpt) SetOwner added in v0.2.15

func (s *CmdOpt) SetOwner(opt OptCmd)

func (*CmdOpt) Short added in v0.2.15

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

func (*CmdOpt) String added in v0.2.15

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

func (*CmdOpt) StringSlice added in v0.2.15

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

func (*CmdOpt) TailPlaceholder added in v0.2.15

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

func (*CmdOpt) Titles added in v0.2.15

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

func (*CmdOpt) Uint added in v0.2.15

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

func (*CmdOpt) Uint64 added in v0.2.15

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

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

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

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

func FindSubCommandRecursive added in v0.2.17

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

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

func (*Command) GetExpandableNames

func (c *Command) GetExpandableNames() string

GetExpandableNames returns the names comma splitted string.

func (*Command) GetExpandableNamesArray

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

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

func (*Command) GetHitStr added in v0.2.11

func (c *Command) GetHitStr() string

GetHitStr returns the matched command string

func (*Command) GetName

func (c *Command) GetName() string

GetName returns the name of a `Command`.

func (*Command) GetOwner added in v0.2.19

func (c *Command) GetOwner() *Command

GetOwner returns the parent command object

func (*Command) GetParentName

func (c *Command) GetParentName() string

GetParentName returns the owner command name

func (*Command) GetQuotedGroupName

func (c *Command) GetQuotedGroupName() string

GetQuotedGroupName returns the group name quoted string.

func (*Command) GetRoot

func (c *Command) GetRoot() *RootCommand

GetRoot returns the `RootCommand`

func (*Command) GetSubCommandNamesBy

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

GetSubCommandNamesBy returns the joint string of subcommands

func (*Command) IsRoot added in v0.2.9

func (c *Command) IsRoot() bool

IsRoot returns true if this command is a RootCommand

func (*Command) PrintHelp

func (c *Command) PrintHelp(justFlags bool)

PrintHelp prints help screen

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 CopierImpl added in v0.2.3

type CopierImpl struct {
	KeepIfFromIsNil  bool // 源字段值为nil指针时,目标字段的值保持不变
	ZeroIfEqualsFrom bool // 源和目标字段值相同时,目标字段被清除为未初始化的零值
	KeepIfFromIsZero bool // 源字段值为未初始化的零值时,目标字段的值保持不变 // 此条尚未实现
}

CopierImpl impl

func (*CopierImpl) Copy added in v0.2.3

func (s *CopierImpl) Copy(toValue interface{}, fromValue interface{}, ignoreNames ...string) (err error)

Copy copy things

type DurationOpt added in v0.2.17

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

DurationOpt for fluent api

func (*DurationOpt) Action added in v0.2.17

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

func (*DurationOpt) Aliases added in v0.2.17

func (s *DurationOpt) Aliases(aliases ...string) (opt OptFlag)

func (*DurationOpt) DefaultValue added in v0.2.17

func (s *DurationOpt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*DurationOpt) Deprecated added in v0.2.17

func (s *DurationOpt) Deprecated(deprecation string) (opt OptFlag)

func (*DurationOpt) Description added in v0.2.17

func (s *DurationOpt) Description(oneLine, long string) (opt OptFlag)

func (*DurationOpt) Examples added in v0.2.17

func (s *DurationOpt) Examples(examples string) (opt OptFlag)

func (*DurationOpt) ExternalTool added in v0.2.17

func (s *DurationOpt) ExternalTool(envKeyName string) (opt OptFlag)

func (*DurationOpt) Group added in v0.2.17

func (s *DurationOpt) Group(group string) (opt OptFlag)

func (*DurationOpt) HeadLike added in v1.0.2

func (s *DurationOpt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*DurationOpt) Hidden added in v0.2.17

func (s *DurationOpt) Hidden(hidden bool) (opt OptFlag)

func (*DurationOpt) Long added in v0.2.17

func (s *DurationOpt) Long(long string) (opt OptFlag)

func (*DurationOpt) OwnerCommand added in v0.2.17

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

func (*DurationOpt) RootCommand added in v0.2.17

func (s *DurationOpt) RootCommand() (root *RootCommand)

func (*DurationOpt) SetOwner added in v0.2.17

func (s *DurationOpt) SetOwner(opt OptCmd)

func (*DurationOpt) Short added in v0.2.17

func (s *DurationOpt) Short(short string) (opt OptFlag)

func (*DurationOpt) Titles added in v0.2.17

func (s *DurationOpt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*DurationOpt) ToggleGroup added in v0.2.17

func (s *DurationOpt) ToggleGroup(group string) (opt OptFlag)

func (*DurationOpt) ValidArgs added in v1.0.2

func (s *DurationOpt) ValidArgs(list ...string) (opt OptFlag)

type ErrorForCmdr added in v1.0.2

type ErrorForCmdr struct {
	Inner     error
	Ignorable bool
	Msg       string
}

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)
}

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

func FindFlag added in v0.2.17

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

FindFlag find flag with `longName` from `cmd`

func FindFlagRecursive added in v0.2.17

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

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

func (*Flag) GetDescZsh added in v0.2.13

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

GetDescZsh temp

func (*Flag) GetTitleFlagNames added in v0.2.13

func (s *Flag) GetTitleFlagNames() string

GetTitleFlagNames temp

func (*Flag) GetTitleFlagNamesBy added in v0.2.13

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

GetTitleFlagNamesBy temp

func (*Flag) GetTitleFlagNamesByMax added in v0.2.13

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

GetTitleFlagNamesByMax temp

func (*Flag) GetTitleZshFlagName added in v0.2.13

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

GetTitleZshFlagName temp

func (*Flag) GetTitleZshFlagNames added in v0.2.13

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

GetTitleZshFlagNames temp

func (*Flag) GetTitleZshFlagNamesArray added in v0.2.13

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

GetTitleZshFlagNamesArray temp

type Float32Opt added in v1.0.1

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

Float32Opt for fluent api

func (*Float32Opt) Action added in v1.0.1

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

func (*Float32Opt) Aliases added in v1.0.1

func (s *Float32Opt) Aliases(aliases ...string) (opt OptFlag)

func (*Float32Opt) DefaultValue added in v1.0.1

func (s *Float32Opt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*Float32Opt) Deprecated added in v1.0.1

func (s *Float32Opt) Deprecated(deprecation string) (opt OptFlag)

func (*Float32Opt) Description added in v1.0.1

func (s *Float32Opt) Description(oneLine, long string) (opt OptFlag)

func (*Float32Opt) Examples added in v1.0.1

func (s *Float32Opt) Examples(examples string) (opt OptFlag)

func (*Float32Opt) ExternalTool added in v1.0.1

func (s *Float32Opt) ExternalTool(envKeyName string) (opt OptFlag)

func (*Float32Opt) Group added in v1.0.1

func (s *Float32Opt) Group(group string) (opt OptFlag)

func (*Float32Opt) HeadLike added in v1.0.2

func (s *Float32Opt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*Float32Opt) Hidden added in v1.0.1

func (s *Float32Opt) Hidden(hidden bool) (opt OptFlag)

func (*Float32Opt) Long added in v1.0.1

func (s *Float32Opt) Long(long string) (opt OptFlag)

func (*Float32Opt) OwnerCommand added in v1.0.1

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

func (*Float32Opt) RootCommand added in v1.0.1

func (s *Float32Opt) RootCommand() (root *RootCommand)

func (*Float32Opt) SetOwner added in v1.0.1

func (s *Float32Opt) SetOwner(opt OptCmd)

func (*Float32Opt) Short added in v1.0.1

func (s *Float32Opt) Short(short string) (opt OptFlag)

func (*Float32Opt) Titles added in v1.0.1

func (s *Float32Opt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*Float32Opt) ToggleGroup added in v1.0.1

func (s *Float32Opt) ToggleGroup(group string) (opt OptFlag)

func (*Float32Opt) ValidArgs added in v1.0.2

func (s *Float32Opt) ValidArgs(list ...string) (opt OptFlag)

type Float64Opt added in v1.0.1

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

Float64Opt for fluent api

func (*Float64Opt) Action added in v1.0.1

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

func (*Float64Opt) Aliases added in v1.0.1

func (s *Float64Opt) Aliases(aliases ...string) (opt OptFlag)

func (*Float64Opt) DefaultValue added in v1.0.1

func (s *Float64Opt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*Float64Opt) Deprecated added in v1.0.1

func (s *Float64Opt) Deprecated(deprecation string) (opt OptFlag)

func (*Float64Opt) Description added in v1.0.1

func (s *Float64Opt) Description(oneLine, long string) (opt OptFlag)

func (*Float64Opt) Examples added in v1.0.1

func (s *Float64Opt) Examples(examples string) (opt OptFlag)

func (*Float64Opt) ExternalTool added in v1.0.1

func (s *Float64Opt) ExternalTool(envKeyName string) (opt OptFlag)

func (*Float64Opt) Group added in v1.0.1

func (s *Float64Opt) Group(group string) (opt OptFlag)

func (*Float64Opt) HeadLike added in v1.0.2

func (s *Float64Opt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*Float64Opt) Hidden added in v1.0.1

func (s *Float64Opt) Hidden(hidden bool) (opt OptFlag)

func (*Float64Opt) Long added in v1.0.1

func (s *Float64Opt) Long(long string) (opt OptFlag)

func (*Float64Opt) OwnerCommand added in v1.0.1

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

func (*Float64Opt) RootCommand added in v1.0.1

func (s *Float64Opt) RootCommand() (root *RootCommand)

func (*Float64Opt) SetOwner added in v1.0.1

func (s *Float64Opt) SetOwner(opt OptCmd)

func (*Float64Opt) Short added in v1.0.1

func (s *Float64Opt) Short(short string) (opt OptFlag)

func (*Float64Opt) Titles added in v1.0.1

func (s *Float64Opt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*Float64Opt) ToggleGroup added in v1.0.1

func (s *Float64Opt) ToggleGroup(group string) (opt OptFlag)

func (*Float64Opt) ValidArgs added in v1.0.2

func (s *Float64Opt) ValidArgs(list ...string) (opt OptFlag)

type HookXrefFunc added in v0.2.11

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

HookXrefFunc the hook function prototype for SetBeforeXrefBuilding and SetAfterXrefBuilt

type Int64Opt added in v0.2.15

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

Int64Opt for fluent api

func (*Int64Opt) Action added in v0.2.15

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

func (*Int64Opt) Aliases added in v0.2.15

func (s *Int64Opt) Aliases(aliases ...string) (opt OptFlag)

func (*Int64Opt) DefaultValue added in v0.2.15

func (s *Int64Opt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*Int64Opt) Deprecated added in v0.2.15

func (s *Int64Opt) Deprecated(deprecation string) (opt OptFlag)

func (*Int64Opt) Description added in v0.2.15

func (s *Int64Opt) Description(oneLine, long string) (opt OptFlag)

func (*Int64Opt) Examples added in v0.2.15

func (s *Int64Opt) Examples(examples string) (opt OptFlag)

func (*Int64Opt) ExternalTool added in v0.2.15

func (s *Int64Opt) ExternalTool(envKeyName string) (opt OptFlag)

func (*Int64Opt) Group added in v0.2.15

func (s *Int64Opt) Group(group string) (opt OptFlag)

func (*Int64Opt) HeadLike added in v1.0.2

func (s *Int64Opt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*Int64Opt) Hidden added in v0.2.15

func (s *Int64Opt) Hidden(hidden bool) (opt OptFlag)

func (*Int64Opt) Long added in v0.2.15

func (s *Int64Opt) Long(long string) (opt OptFlag)

func (*Int64Opt) OwnerCommand added in v0.2.15

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

func (*Int64Opt) RootCommand added in v0.2.15

func (s *Int64Opt) RootCommand() (root *RootCommand)

func (*Int64Opt) SetOwner added in v0.2.15

func (s *Int64Opt) SetOwner(opt OptCmd)

func (*Int64Opt) Short added in v0.2.15

func (s *Int64Opt) Short(short string) (opt OptFlag)

func (*Int64Opt) Titles added in v0.2.15

func (s *Int64Opt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*Int64Opt) ToggleGroup added in v0.2.15

func (s *Int64Opt) ToggleGroup(group string) (opt OptFlag)

func (*Int64Opt) ValidArgs added in v1.0.2

func (s *Int64Opt) ValidArgs(list ...string) (opt OptFlag)

type IntOpt added in v0.2.15

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

IntOpt for fluent api

func (*IntOpt) Action added in v0.2.15

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

func (*IntOpt) Aliases added in v0.2.15

func (s *IntOpt) Aliases(aliases ...string) (opt OptFlag)

func (*IntOpt) DefaultValue added in v0.2.15

func (s *IntOpt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*IntOpt) Deprecated added in v0.2.15

func (s *IntOpt) Deprecated(deprecation string) (opt OptFlag)

func (*IntOpt) Description added in v0.2.15

func (s *IntOpt) Description(oneLine, long string) (opt OptFlag)

func (*IntOpt) Examples added in v0.2.15

func (s *IntOpt) Examples(examples string) (opt OptFlag)

func (*IntOpt) ExternalTool added in v0.2.15

func (s *IntOpt) ExternalTool(envKeyName string) (opt OptFlag)

func (*IntOpt) Group added in v0.2.15

func (s *IntOpt) Group(group string) (opt OptFlag)

func (*IntOpt) HeadLike added in v1.0.2

func (s *IntOpt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*IntOpt) Hidden added in v0.2.15

func (s *IntOpt) Hidden(hidden bool) (opt OptFlag)

func (*IntOpt) Long added in v0.2.15

func (s *IntOpt) Long(long string) (opt OptFlag)

func (*IntOpt) OwnerCommand added in v0.2.15

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

func (*IntOpt) RootCommand added in v0.2.15

func (s *IntOpt) RootCommand() (root *RootCommand)

func (*IntOpt) SetOwner added in v0.2.15

func (s *IntOpt) SetOwner(opt OptCmd)

func (*IntOpt) Short added in v0.2.15

func (s *IntOpt) Short(short string) (opt OptFlag)

func (*IntOpt) Titles added in v0.2.15

func (s *IntOpt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*IntOpt) ToggleGroup added in v0.2.15

func (s *IntOpt) ToggleGroup(group string) (opt OptFlag)

func (*IntOpt) ValidArgs added in v1.0.2

func (s *IntOpt) ValidArgs(list ...string) (opt OptFlag)

type IntSliceOpt added in v0.2.15

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

IntSliceOpt for fluent api

func (*IntSliceOpt) Action added in v0.2.15

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

func (*IntSliceOpt) Aliases added in v0.2.15

func (s *IntSliceOpt) Aliases(aliases ...string) (opt OptFlag)

func (*IntSliceOpt) DefaultValue added in v0.2.15

func (s *IntSliceOpt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*IntSliceOpt) Deprecated added in v0.2.15

func (s *IntSliceOpt) Deprecated(deprecation string) (opt OptFlag)

func (*IntSliceOpt) Description added in v0.2.15

func (s *IntSliceOpt) Description(oneLine, long string) (opt OptFlag)

func (*IntSliceOpt) Examples added in v0.2.15

func (s *IntSliceOpt) Examples(examples string) (opt OptFlag)

func (*IntSliceOpt) ExternalTool added in v0.2.15

func (s *IntSliceOpt) ExternalTool(envKeyName string) (opt OptFlag)

func (*IntSliceOpt) Group added in v0.2.15

func (s *IntSliceOpt) Group(group string) (opt OptFlag)

func (*IntSliceOpt) HeadLike added in v1.0.2

func (s *IntSliceOpt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*IntSliceOpt) Hidden added in v0.2.15

func (s *IntSliceOpt) Hidden(hidden bool) (opt OptFlag)

func (*IntSliceOpt) Long added in v0.2.15

func (s *IntSliceOpt) Long(long string) (opt OptFlag)

func (*IntSliceOpt) OwnerCommand added in v0.2.15

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

func (*IntSliceOpt) RootCommand added in v0.2.15

func (s *IntSliceOpt) RootCommand() (root *RootCommand)

func (*IntSliceOpt) SetOwner added in v0.2.15

func (s *IntSliceOpt) SetOwner(opt OptCmd)

func (*IntSliceOpt) Short added in v0.2.15

func (s *IntSliceOpt) Short(short string) (opt OptFlag)

func (*IntSliceOpt) Titles added in v0.2.15

func (s *IntSliceOpt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*IntSliceOpt) ToggleGroup added in v0.2.15

func (s *IntSliceOpt) ToggleGroup(group string) (opt OptFlag)

func (*IntSliceOpt) ValidArgs added in v1.0.2

func (s *IntSliceOpt) ValidArgs(list ...string) (opt OptFlag)

type Opt added in v0.2.15

type Opt interface {
	Titles(short, long string, aliases ...string) (opt Opt)
	Short(short string) (opt Opt)
	Long(long string) (opt Opt)
	Aliases(ss ...string) (opt Opt)
	Description(oneLine, long string) (opt Opt)
	Examples(examples string) (opt Opt)
	Group(group string) (opt Opt)
	Hidden(hidden bool) (opt Opt)
	Deprecated(deprecation string) (opt Opt)
	Action(action func(cmd *Command, args []string) (err error)) (opt Opt)
}

Opt never used?

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 NewCmd added in v0.2.17

func NewCmd() (opt OptCmd)

NewCmd for fluent api

func NewCmdFrom added in v0.2.17

func NewCmdFrom(cmd *Command) (opt OptCmd)

NewCmdFrom for fluent api

func NewSubCmd added in v0.2.17

func NewSubCmd() (opt OptCmd)

NewSubCmd 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)

	OwnerCommand() (opt OptCmd)
	SetOwner(opt OptCmd)

	RootCommand() *RootCommand
}

OptFlag to support fluent api of cmdr. see also: cmdr.Root().NewSubCommand()/.NewFlag()

func NewBool added in v0.2.17

func NewBool() (opt OptFlag)

NewBool for fluent api

func NewDuration added in v0.2.17

func NewDuration() (opt OptFlag)

NewDuration for fluent api

func NewFloat32 added in v1.0.1

func NewFloat32() (opt OptFlag)

NewFloat32 for fluent api

func NewFloat64 added in v1.0.1

func NewFloat64() (opt OptFlag)

NewFloat64 for fluent api

func NewInt added in v0.2.17

func NewInt() (opt OptFlag)

NewInt for fluent api

func NewInt64 added in v0.2.17

func NewInt64() (opt OptFlag)

NewInt64 for fluent api

func NewIntSlice added in v0.2.17

func NewIntSlice() (opt OptFlag)

NewIntSlice for fluent api

func NewString added in v0.2.17

func NewString() (opt OptFlag)

NewString for fluent api

func NewStringSlice added in v0.2.17

func NewStringSlice() (opt OptFlag)

NewStringSlice for fluent api

func NewUint added in v0.2.17

func NewUint() (opt OptFlag)

NewUint for fluent api

func NewUint64 added in v0.2.17

func NewUint64() (opt OptFlag)

NewUint64 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: ```golang root := cmdr.Root() co := root.NewSubCommand() co.NewFlag(cmdr.OptFlagTypeUint) ```

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 slice flag
	OptFlagTypeFloat32 OptFlagType = iota + 8
	// OptFlagTypeFloat64 to create a new int slice 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 NewOptions

func NewOptions() *Options

NewOptions returns an `Options` structure pointer

func NewOptionsWith

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

NewOptionsWith returns an `Options` structure pointer

func (*Options) DumpAsString

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

DumpAsString for debugging.

func (*Options) Get

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

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

func (*Options) GetBool

func (s *Options) GetBool(key string) (ret bool)

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

func (*Options) GetDuration added in v0.2.11

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

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

func (*Options) GetFloat32 added in v1.0.1

func (s *Options) GetFloat32(key string) (ir float32)

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

func (*Options) GetFloat64 added in v1.0.1

func (s *Options) GetFloat64(key string) (ir float64)

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

func (*Options) GetHierarchyList added in v0.2.17

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

GetHierarchyList returns the hierarchy data for dumping

func (*Options) GetInt

func (s *Options) GetInt(key string) (ir int64)

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

func (*Options) GetIntSlice added in v0.2.11

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

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

func (*Options) GetMap added in v1.0.0

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

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

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

func (*Options) GetStringSlice

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

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

func (*Options) GetUint added in v0.2.3

func (s *Options) GetUint(key string) (ir uint64)

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

func (*Options) LoadConfigFile

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

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.

func (*Options) Set

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

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 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, create an new RootCommand

func (*RootCmdOpt) Action added in v0.2.15

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

func (*RootCmdOpt) Aliases added in v0.2.15

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

func (*RootCmdOpt) Bool added in v0.2.15

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

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 (s *RootCmdOpt) Deprecated(deprecation string) (opt OptCmd)

func (*RootCmdOpt) Description added in v0.2.15

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

func (*RootCmdOpt) Duration added in v0.2.17

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

func (*RootCmdOpt) Examples added in v0.2.15

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

func (*RootCmdOpt) Float32 added in v1.0.1

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

func (*RootCmdOpt) Float64 added in v1.0.1

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

func (*RootCmdOpt) Group added in v0.2.15

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

func (*RootCmdOpt) Header added in v0.2.15

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

Header for fluent api

func (*RootCmdOpt) Hidden added in v0.2.15

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

func (*RootCmdOpt) Int added in v0.2.15

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

func (*RootCmdOpt) Int64 added in v0.2.15

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

func (*RootCmdOpt) IntSlice added in v0.2.15

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

func (*RootCmdOpt) Long added in v0.2.15

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

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 (s *RootCmdOpt) PostAction(pre func(cmd *Command, args []string)) (opt OptCmd)

func (*RootCmdOpt) PreAction added in v0.2.15

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

func (*RootCmdOpt) RootCommand added in v0.2.15

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

func (*RootCmdOpt) SetOwner added in v0.2.15

func (s *RootCmdOpt) SetOwner(opt OptCmd)

func (*RootCmdOpt) Short added in v0.2.15

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

func (*RootCmdOpt) String added in v0.2.15

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

func (*RootCmdOpt) StringSlice added in v0.2.15

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

func (*RootCmdOpt) TailPlaceholder added in v0.2.15

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

func (*RootCmdOpt) Titles added in v0.2.15

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

func (*RootCmdOpt) Uint added in v0.2.15

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

func (*RootCmdOpt) Uint64 added in v0.2.15

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

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 StringOpt added in v0.2.15

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

StringOpt for fluent api

func (*StringOpt) Action added in v0.2.15

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

func (*StringOpt) Aliases added in v0.2.15

func (s *StringOpt) Aliases(aliases ...string) (opt OptFlag)

func (*StringOpt) DefaultValue added in v0.2.15

func (s *StringOpt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*StringOpt) Deprecated added in v0.2.15

func (s *StringOpt) Deprecated(deprecation string) (opt OptFlag)

func (*StringOpt) Description added in v0.2.15

func (s *StringOpt) Description(oneLine, long string) (opt OptFlag)

func (*StringOpt) Examples added in v0.2.15

func (s *StringOpt) Examples(examples string) (opt OptFlag)

func (*StringOpt) ExternalTool added in v0.2.15

func (s *StringOpt) ExternalTool(envKeyName string) (opt OptFlag)

func (*StringOpt) Group added in v0.2.15

func (s *StringOpt) Group(group string) (opt OptFlag)

func (*StringOpt) HeadLike added in v1.0.2

func (s *StringOpt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*StringOpt) Hidden added in v0.2.15

func (s *StringOpt) Hidden(hidden bool) (opt OptFlag)

func (*StringOpt) Long added in v0.2.15

func (s *StringOpt) Long(long string) (opt OptFlag)

func (*StringOpt) OwnerCommand added in v0.2.15

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

func (*StringOpt) RootCommand added in v0.2.15

func (s *StringOpt) RootCommand() (root *RootCommand)

func (*StringOpt) SetOwner added in v0.2.15

func (s *StringOpt) SetOwner(opt OptCmd)

func (*StringOpt) Short added in v0.2.15

func (s *StringOpt) Short(short string) (opt OptFlag)

func (*StringOpt) Titles added in v0.2.15

func (s *StringOpt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*StringOpt) ToggleGroup added in v0.2.15

func (s *StringOpt) ToggleGroup(group string) (opt OptFlag)

func (*StringOpt) ValidArgs added in v1.0.2

func (s *StringOpt) ValidArgs(list ...string) (opt OptFlag)

type StringSliceOpt added in v0.2.15

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

StringSliceOpt for fluent api

func (*StringSliceOpt) Action added in v0.2.15

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

func (*StringSliceOpt) Aliases added in v0.2.15

func (s *StringSliceOpt) Aliases(aliases ...string) (opt OptFlag)

func (*StringSliceOpt) DefaultValue added in v0.2.15

func (s *StringSliceOpt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*StringSliceOpt) Deprecated added in v0.2.15

func (s *StringSliceOpt) Deprecated(deprecation string) (opt OptFlag)

func (*StringSliceOpt) Description added in v0.2.15

func (s *StringSliceOpt) Description(oneLine, long string) (opt OptFlag)

func (*StringSliceOpt) Examples added in v0.2.15

func (s *StringSliceOpt) Examples(examples string) (opt OptFlag)

func (*StringSliceOpt) ExternalTool added in v0.2.15

func (s *StringSliceOpt) ExternalTool(envKeyName string) (opt OptFlag)

func (*StringSliceOpt) Group added in v0.2.15

func (s *StringSliceOpt) Group(group string) (opt OptFlag)

func (*StringSliceOpt) HeadLike added in v1.0.2

func (s *StringSliceOpt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*StringSliceOpt) Hidden added in v0.2.15

func (s *StringSliceOpt) Hidden(hidden bool) (opt OptFlag)

func (*StringSliceOpt) Long added in v0.2.15

func (s *StringSliceOpt) Long(long string) (opt OptFlag)

func (*StringSliceOpt) OwnerCommand added in v0.2.15

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

func (*StringSliceOpt) RootCommand added in v0.2.15

func (s *StringSliceOpt) RootCommand() (root *RootCommand)

func (*StringSliceOpt) SetOwner added in v0.2.15

func (s *StringSliceOpt) SetOwner(opt OptCmd)

func (*StringSliceOpt) Short added in v0.2.15

func (s *StringSliceOpt) Short(short string) (opt OptFlag)

func (*StringSliceOpt) Titles added in v0.2.15

func (s *StringSliceOpt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*StringSliceOpt) ToggleGroup added in v0.2.15

func (s *StringSliceOpt) ToggleGroup(group string) (opt OptFlag)

func (*StringSliceOpt) ValidArgs added in v1.0.2

func (s *StringSliceOpt) ValidArgs(list ...string) (opt OptFlag)

type SubCmdOpt added in v0.2.15

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

SubCmdOpt for fluent api

func (*SubCmdOpt) Action added in v0.2.15

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

func (*SubCmdOpt) Aliases added in v0.2.15

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

func (*SubCmdOpt) Bool added in v0.2.15

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

func (*SubCmdOpt) Deprecated added in v0.2.15

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

func (*SubCmdOpt) Description added in v0.2.15

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

func (*SubCmdOpt) Duration added in v0.2.17

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

func (*SubCmdOpt) Examples added in v0.2.15

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

func (*SubCmdOpt) Float32 added in v1.0.1

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

func (*SubCmdOpt) Float64 added in v1.0.1

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

func (*SubCmdOpt) Group added in v0.2.15

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

func (*SubCmdOpt) Hidden added in v0.2.15

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

func (*SubCmdOpt) Int added in v0.2.15

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

func (*SubCmdOpt) Int64 added in v0.2.15

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

func (*SubCmdOpt) IntSlice added in v0.2.15

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

func (*SubCmdOpt) Long added in v0.2.15

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

func (*SubCmdOpt) NewFlag added in v0.2.15

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

func (*SubCmdOpt) NewSubCommand added in v0.2.15

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

func (*SubCmdOpt) OwnerCommand added in v0.2.15

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

func (*SubCmdOpt) PostAction added in v0.2.15

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

func (*SubCmdOpt) PreAction added in v0.2.15

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

func (*SubCmdOpt) RootCommand added in v0.2.15

func (s *SubCmdOpt) RootCommand() (root *RootCommand)

func (*SubCmdOpt) SetOwner added in v0.2.15

func (s *SubCmdOpt) SetOwner(opt OptCmd)

func (*SubCmdOpt) Short added in v0.2.15

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

func (*SubCmdOpt) String added in v0.2.15

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

func (*SubCmdOpt) StringSlice added in v0.2.15

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

func (*SubCmdOpt) TailPlaceholder added in v0.2.15

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

func (*SubCmdOpt) Titles added in v0.2.15

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

func (*SubCmdOpt) Uint added in v0.2.15

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

func (*SubCmdOpt) Uint64 added in v0.2.15

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

type Uint64Opt added in v0.2.15

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

Uint64Opt for fluent api

func (*Uint64Opt) Action added in v0.2.15

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

func (*Uint64Opt) Aliases added in v0.2.15

func (s *Uint64Opt) Aliases(aliases ...string) (opt OptFlag)

func (*Uint64Opt) DefaultValue added in v0.2.15

func (s *Uint64Opt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*Uint64Opt) Deprecated added in v0.2.15

func (s *Uint64Opt) Deprecated(deprecation string) (opt OptFlag)

func (*Uint64Opt) Description added in v0.2.15

func (s *Uint64Opt) Description(oneLine, long string) (opt OptFlag)

func (*Uint64Opt) Examples added in v0.2.15

func (s *Uint64Opt) Examples(examples string) (opt OptFlag)

func (*Uint64Opt) ExternalTool added in v0.2.15

func (s *Uint64Opt) ExternalTool(envKeyName string) (opt OptFlag)

func (*Uint64Opt) Group added in v0.2.15

func (s *Uint64Opt) Group(group string) (opt OptFlag)

func (*Uint64Opt) HeadLike added in v1.0.2

func (s *Uint64Opt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*Uint64Opt) Hidden added in v0.2.15

func (s *Uint64Opt) Hidden(hidden bool) (opt OptFlag)

func (*Uint64Opt) Long added in v0.2.15

func (s *Uint64Opt) Long(long string) (opt OptFlag)

func (*Uint64Opt) OwnerCommand added in v0.2.15

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

func (*Uint64Opt) RootCommand added in v0.2.15

func (s *Uint64Opt) RootCommand() (root *RootCommand)

func (*Uint64Opt) SetOwner added in v0.2.15

func (s *Uint64Opt) SetOwner(opt OptCmd)

func (*Uint64Opt) Short added in v0.2.15

func (s *Uint64Opt) Short(short string) (opt OptFlag)

func (*Uint64Opt) Titles added in v0.2.15

func (s *Uint64Opt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*Uint64Opt) ToggleGroup added in v0.2.15

func (s *Uint64Opt) ToggleGroup(group string) (opt OptFlag)

func (*Uint64Opt) ValidArgs added in v1.0.2

func (s *Uint64Opt) ValidArgs(list ...string) (opt OptFlag)

type UintOpt added in v0.2.15

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

UintOpt for fluent api

func (*UintOpt) Action added in v0.2.15

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

func (*UintOpt) Aliases added in v0.2.15

func (s *UintOpt) Aliases(aliases ...string) (opt OptFlag)

func (*UintOpt) DefaultValue added in v0.2.15

func (s *UintOpt) DefaultValue(val interface{}, placeholder string) (opt OptFlag)

func (*UintOpt) Deprecated added in v0.2.15

func (s *UintOpt) Deprecated(deprecation string) (opt OptFlag)

func (*UintOpt) Description added in v0.2.15

func (s *UintOpt) Description(oneLine, long string) (opt OptFlag)

func (*UintOpt) Examples added in v0.2.15

func (s *UintOpt) Examples(examples string) (opt OptFlag)

func (*UintOpt) ExternalTool added in v0.2.15

func (s *UintOpt) ExternalTool(envKeyName string) (opt OptFlag)

func (*UintOpt) Group added in v0.2.15

func (s *UintOpt) Group(group string) (opt OptFlag)

func (*UintOpt) HeadLike added in v1.0.2

func (s *UintOpt) HeadLike(enable bool, min, max int64) (opt OptFlag)

func (*UintOpt) Hidden added in v0.2.15

func (s *UintOpt) Hidden(hidden bool) (opt OptFlag)

func (*UintOpt) Long added in v0.2.15

func (s *UintOpt) Long(long string) (opt OptFlag)

func (*UintOpt) OwnerCommand added in v0.2.15

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

func (*UintOpt) RootCommand added in v0.2.15

func (s *UintOpt) RootCommand() (root *RootCommand)

func (*UintOpt) SetOwner added in v0.2.15

func (s *UintOpt) SetOwner(opt OptCmd)

func (*UintOpt) Short added in v0.2.15

func (s *UintOpt) Short(short string) (opt OptFlag)

func (*UintOpt) Titles added in v0.2.15

func (s *UintOpt) Titles(short, long string, aliases ...string) (opt OptFlag)

func (*UintOpt) ToggleGroup added in v0.2.15

func (s *UintOpt) ToggleGroup(group string) (opt OptFlag)

func (*UintOpt) ValidArgs added in v1.0.2

func (s *UintOpt) ValidArgs(list ...string) (opt OptFlag)

Directories

Path Synopsis
examples
plugin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL