cli

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

README

CLI

About the project

CLI provides a higher level and more friendly interfaces to build modern command line interfaces and manage configurations for Go applications.

It is based on

Status

Working in process

Concepts

A cli is composed of commands, arguments and flags.

Commands represent actions, Args are things and Flags are modifiers for those actions.

The pattern to follow is appname commands args --flag

The flag is compatible with the GNU extensions to the POSIX recommendations for command-line options.

Getting Started

Commands

You can migrate your cobra commands to CLI easily. The cli.NewCommand receives a *cobra.Command to build the command line interface.

import (
	"github.com/caicloud/nirvana/cli"
	"github.com/spf13/cobra"
)

func main() {
	cmd := cli.NewCommand(&cobra.Command{
		Use:  "example",
		Long: "this is an cli example",
		Run: func(cmd *cobra.Command, args []string) {
			// your code
		},
	})
}

More about cobra command

Flags

Flag, different from pflag.Flag, is an interface containing the following methods in CLI. And it is declarative in CLI, unlike in Cobra where it is imperative, which makes the flags more readable.

// Flag describes a flag interface
type Flag interface {
	// IsPersistent specify whether the flag is persistent
	IsPersistent() bool
	// GetName returns the flag's name
	GetName() string
	// ApplyTo adds the flag to a given FlagSet
	ApplyTo(*pflag.FlagSet) error
}

A most widely used string flag is defined like

type StringFlag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue string
	// points to a variable in which to store the value of the flag
	Destination *string
}
Binding flag with ENV

CLI supports the ability to bind your flags with ENV variables.

CLI uses the following precedence order. Each item takes precedence over the item below it.

  • explicit calls to set
  • flag
  • env
  • default value
f := cli.StringFlag{
	Name: "log",
	EnvKey: "LOG",
  	DefValue: "test",
}
Automatic ENV and Prefix

CLI supports the ability to bind you flags with ENV and add prefix automatically

The following methods exist to aid working with ENV:

  • AutomaticEnv(): It tells CLI to bind all flags with ENV automatically.
  • SetEnvPrefix(string): It is always working with AutomaticEnv . It makes CLI add a prefix while reading from env variables.
  • SetEnvKeyReplacer(*strings.Replacer): It makes CLI change the ENV by key replacer. For example, you can set a UnderlineReplacer to replace all - with _ .

When working with ENV variables, it’s important to recognize that CLI treats ENV variables case insensitively. All ENV variables are treated as UPPER case

Note: If EnvKey is set, it will override the automatic env and does not automatically add the prefix.

Example

AutomaticEnv()
SetEnvPrefix("nirvana")

log = new(string)

f := cli.StringFlag{
	Name: "log",
	Destination: log,
}

os.Setenv("NIRVANA_LOG", "TEST")

cmd.AddFlag(f)

// *log is TEST
Hidden, Deprecated, ShorthandDeprecated
  • Hidden and Deprecated hide the whole flag in help information.
  • ShorthandDeprecated hides the shorhand flag.

You can set the flag as usual.

  • Hidden just hide the flag
  • Deprecated and ShorthandDeprecated will print a deprecated message to you if you use the flag
Persistent

Persistent option makes the flag can be inherited by it children‘s commands

Configuration

CLI can be also treated as a configuration registry.

The flags are bound to registry automatically. That means all defined flags' values can be accessed by Get() function.

cmd.AddFlag(cli.StringFlag{Name: "log", DefValue: "test configuration"})
cli.GetString("log") // test configuration
Reading Config Files

There are two ways for you to let CLI know where to look for config files.

  1. SetConfigFile(in string)
  2. SetConfigPaths(noExtName string, paths …string)

SetConfigFile explicitly defines the path, name and extension of the config file. CLI will use this and not check any of the config paths.

SetConfigPaths defines a config file name without the extension and paths where CLI search the config file in.

Then, use

  • ReadInConfig
  • MergeInConfig

to load configuration files.

The difference between ReadInConfig and MergeInConfig is that ReadInConfig discards all existing config but MergeInConfig merges the configuration with existing one.

Watching and reloading config files

After setting config file path, working with WatchConfig(onChange func(in fsnotify.Event)) to watch the config file changes.

If the watched config file is created/deleted/updated, CLI will read new values from config file automatically. Then the onChange callback function is invoked.

cli.SetConfigFile("/etc/nirvana/config.json")
cli.WatchConfig(func(e fsnotify.Event){
	fmt.Println("Config file changed: ", e.Name)
})
Reading Config from io.Reader

CLI supports the ability to let you implement your own required configuration source and feed it to CLI.

But the prerequisite is that CLI should known what type it is.

Using SetConfigType(in string) to tell CLI the type of configuration. The following type are supported now:

  • json
  • toml
  • yaml or yml
  • hcl
  • properties, props, prop
Getting Values From CLI

The following methods exist to aid getting values from CLI.

  • Get(key string) interface{}
  • IsSet(key string) bool
  • GetBool(key string) bool
  • GetDuration(key string) time.Duration
  • GetFloat32(key string) float32
  • GetFloat64(key string) float64
  • GetInt(key string) int
  • GetInt32(key string) int32
  • GetInt64(key string) int64
  • GetString(key string) string
  • GetStringSlice(key string) []string
  • GetUint(key string) uint
  • GetUint32(key string) uint32
  • GetUint64(key string) uint64

Note that each Get function will return a zero value if it is not found. To check if a given key exists, please use IsSet()

Thanks

Thanks spf13 for creating awesome tools to make it easier to build beautiful modern CLI apps.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UnderlineReplacer replace dash of underline
	UnderlineReplacer = strings.NewReplacer("-", "_")
)

Functions

func AllKeys

func AllKeys() []string

AllKeys returns all keys holding a value, regardless of where they are set. Nested keys are returned with a v.keyDelim (= ".") separator

func AllSettings

func AllSettings() map[string]interface{}

AllSettings merges all settings and returns them as a map[string]interface{}.

func AutomaticEnv

func AutomaticEnv()

AutomaticEnv has Mamba check ENV variables for all. keys set in config, default & flags

func Get

func Get(key string) interface{}

Get can retrieve any value given the key to use. Get is case-insensitive for a key. Get has the behavior of returning the value associated with the first place from where it is set. Viper will check in the following order: override, flag, env, config file, key/value store, default

Get returns an interface. For a specific value use one of the Get____ methods.

func GetBool

func GetBool(key string) bool

GetBool returns the value associated with the key as a bool.

func GetDuration

func GetDuration(key string) time.Duration

GetDuration returns the value associated with the key as a time.Duration.

func GetFloat32

func GetFloat32(key string) float32

GetFloat32 returns the value associated with the key as a float32.

func GetFloat64

func GetFloat64(key string) float64

GetFloat64 returns the value associated with the key as a float64.

func GetInt

func GetInt(key string) int

GetInt returns the value associated with the key as a int.

func GetInt32

func GetInt32(key string) int32

GetInt32 returns the value associated with the key as a int32.

func GetInt64

func GetInt64(key string) int64

GetInt64 returns the value associated with the key as a int64.

func GetString

func GetString(key string) string

GetString returns the value associated with the key as a string.

func GetStringSlice

func GetStringSlice(key string) []string

GetStringSlice returns the value associated with the key as a []string.

func GetUint

func GetUint(key string) uint

GetUint returns the value associated with the key as a uint.

func GetUint32

func GetUint32(key string) uint32

GetUint32 returns the value associated with the key as a uint32.

func GetUint64

func GetUint64(key string) uint64

GetUint64 returns the value associated with the key as a uint64.

func IsSet

func IsSet(key string) bool

IsSet checks to see if the key has been set in any of the data locations. IsSet is case-insensitive for a key

func MergeConfig

func MergeConfig(in io.Reader) error

MergeConfig merges a new configuration with an existing config. You should SetConfigType before read config

func MergeInConfig

func MergeInConfig() error

MergeInConfig merges a new configuration with an existing config.

func ReadConfig

func ReadConfig(in io.Reader) error

ReadConfig will read a configuration file, setting existing keys to nil if the key does not exist in the file. You should SetConfigType before read config

func ReadInConfig

func ReadInConfig() error

ReadInConfig will discover and load the configuration file from disk and key/value stores, searching in one of the defined paths.

func Reset

func Reset()

Reset intends for testing, will reset all to default settings. In the public interface for the viper package so applications can use it in their testing as well.

func Set

func Set(key string, value interface{})

Set sets the value for the key in the override regiser. Set is case-insensitive for a key. Will be used instead of values obtained via flags, config file, ENV, default, or key/value store.

func SetConfigFile

func SetConfigFile(in string)

SetConfigFile explicitly defines the path, name and extension of the config file. Viper will use this and not check any of the config paths.

func SetConfigPaths

func SetConfigPaths(noExtName string, paths ...string)

SetConfigPaths adds paths for Viper to search for the config file in. The given file name should not contain a extension, e.g. 'json'.

func SetConfigType

func SetConfigType(in string) error

SetConfigType sets the type of the configuration, e.g. "json".

func SetEnvKeyReplacer

func SetEnvKeyReplacer(r *strings.Replacer)

SetEnvKeyReplacer sets the strings.Replacer on the viper object Useful for mapping an environmental variable to a key that does not match it.

func SetEnvPrefix

func SetEnvPrefix(in string)

SetEnvPrefix defines a prefix that ENVIRONMENT variables will use. E.g. if your prefix is "spf", the env registry will look for env variables that start with "SPF_". Only work for automatic env

func WatchConfig

func WatchConfig(onChange func(in fsnotify.Event))

WatchConfig watches the configuration file change

Types

type BoolFlag

type BoolFlag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue bool
	// points to a variable in which to store the value of the flag
	Destination *bool
}

BoolFlag is a flag of type bool

func (BoolFlag) ApplyTo

func (f BoolFlag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (BoolFlag) GetName

func (f BoolFlag) GetName() string

GetName returns the flag's name

func (BoolFlag) IsPersistent

func (f BoolFlag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type Command

type Command struct {
	*cobra.Command
}

Command contains a cobra.Command

func NewCommand

func NewCommand(cmd *cobra.Command) *Command

NewCommand returns a a Command

func (*Command) AddCobraCommand

func (c *Command) AddCobraCommand(cmds ...*cobra.Command)

AddCobraCommand adds one or more cobra commands to this parent command.

func (*Command) AddCommand

func (c *Command) AddCommand(cmds ...*Command)

AddCommand adds one or more commands to this parent command.

func (*Command) AddFlag

func (c *Command) AddFlag(fs ...Flag) error

AddFlag adds one or more commands to this command

func (*Command) CobraCommands

func (c *Command) CobraCommands() []*cobra.Command

CobraCommands returns a sorted slice of child cobra commands.

func (*Command) Commands

func (c *Command) Commands() []*Command

Commands returns a sorted slice of child commands.

func (*Command) RemoveCobraCommand

func (c *Command) RemoveCobraCommand(cmds ...*cobra.Command)

RemoveCobraCommand removes one or more cobra commands from a parent command.

func (*Command) RemoveCommand

func (c *Command) RemoveCommand(cmds ...*Command)

RemoveCommand removes one or more commands from a parent command.

type DurationFlag

type DurationFlag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue time.Duration
	// points to a variable in which to store the value of the flag
	Destination *time.Duration
}

DurationFlag is a flag of type time.Duration

func (DurationFlag) ApplyTo

func (f DurationFlag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (DurationFlag) GetName

func (f DurationFlag) GetName() string

GetName returns the flag's name

func (DurationFlag) IsPersistent

func (f DurationFlag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type Flag

type Flag interface {
	// IsPersistent specify whether the flag is persistent
	IsPersistent() bool
	// GetName returns the flag's name
	GetName() string
	// ApplyTo adds the flag to a given FlagSet
	ApplyTo(*pflag.FlagSet) error
}

Flag describes a flag interface

type Float32Flag

type Float32Flag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue float32
	// points to a variable in which to store the value of the flag
	Destination *float32
}

Float32Flag is a flag of type float32

func (Float32Flag) ApplyTo

func (f Float32Flag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (Float32Flag) GetName

func (f Float32Flag) GetName() string

GetName returns the flag's name

func (Float32Flag) IsPersistent

func (f Float32Flag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type Float64Flag

type Float64Flag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue float64
	// points to a variable in which to store the value of the flag
	Destination *float64
}

Float64Flag is a flag of type float64

func (Float64Flag) ApplyTo

func (f Float64Flag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (Float64Flag) GetName

func (f Float64Flag) GetName() string

GetName returns the flag's name

func (Float64Flag) IsPersistent

func (f Float64Flag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type Int32Flag

type Int32Flag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue int32
	// points to a variable in which to store the value of the flag
	Destination *int32
}

Int32Flag is a flag of type int32

func (Int32Flag) ApplyTo

func (f Int32Flag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (Int32Flag) GetName

func (f Int32Flag) GetName() string

GetName returns the flag's name

func (Int32Flag) IsPersistent

func (f Int32Flag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type Int64Flag

type Int64Flag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue int64
	// points to a variable in which to store the value of the flag
	Destination *int64
}

Int64Flag is a flag of type int64

func (Int64Flag) ApplyTo

func (f Int64Flag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (Int64Flag) GetName

func (f Int64Flag) GetName() string

GetName returns the flag's name

func (Int64Flag) IsPersistent

func (f Int64Flag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type IntFlag

type IntFlag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue int
	// points to a variable in which to store the value of the flag
	Destination *int
}

IntFlag is a flag of type int

func (IntFlag) ApplyTo

func (f IntFlag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (IntFlag) GetName

func (f IntFlag) GetName() string

GetName returns the flag's name

func (IntFlag) IsPersistent

func (f IntFlag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type StringFlag

type StringFlag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue string
	// points to a variable in which to store the value of the flag
	Destination *string
}

StringFlag is a flag of type string

func (StringFlag) ApplyTo

func (f StringFlag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (StringFlag) GetName

func (f StringFlag) GetName() string

GetName returns the flag's name

func (StringFlag) IsPersistent

func (f StringFlag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type StringSliceFlag

type StringSliceFlag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue []string
	// points to a variable in which to store the value of the flag
	Destination *[]string
}

StringSliceFlag is a flag of type []string

func (StringSliceFlag) ApplyTo

func (f StringSliceFlag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (StringSliceFlag) GetName

func (f StringSliceFlag) GetName() string

GetName returns the flag's name

func (StringSliceFlag) IsPersistent

func (f StringSliceFlag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type Uint32Flag

type Uint32Flag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue uint32
	// points to a variable in which to store the value of the flag
	Destination *uint32
}

Uint32Flag is a flag of type uint32

func (Uint32Flag) ApplyTo

func (f Uint32Flag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (Uint32Flag) GetName

func (f Uint32Flag) GetName() string

GetName returns the flag's name

func (Uint32Flag) IsPersistent

func (f Uint32Flag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type Uint64Flag

type Uint64Flag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue uint64
	// points to a variable in which to store the value of the flag
	Destination *uint64
}

Uint64Flag is a flag of type uint64

func (Uint64Flag) ApplyTo

func (f Uint64Flag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (Uint64Flag) GetName

func (f Uint64Flag) GetName() string

GetName returns the flag's name

func (Uint64Flag) IsPersistent

func (f Uint64Flag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

type UintFlag

type UintFlag struct {
	// Name as it appears on command line
	Name string
	// one-letter abbreviated flag
	Shorthand string
	// help message
	Usage string
	// specify whether the flag is persistent
	Persistent bool
	// used by cobra.Command bash autocomple code
	Annotations map[string][]string
	// If this flag is deprecated, this string is the new or now thing to use
	Deprecated string
	// If the shorthand of this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string
	// used by cobra.Command to allow flags to be hidden from help/usage text
	Hidden bool
	// bind the flag to env key, you can use AutomaticEnv to bind all flags to env automatically
	// if EnvKey is set, it will override the automatic generated env key
	EnvKey string
	// the default value
	DefValue uint
	// points to a variable in which to store the value of the flag
	Destination *uint
}

UintFlag is a flag of type uint

func (UintFlag) ApplyTo

func (f UintFlag) ApplyTo(fs *pflag.FlagSet) error

ApplyTo adds the flag to given FlagSet

func (UintFlag) GetName

func (f UintFlag) GetName() string

GetName returns the flag's name

func (UintFlag) IsPersistent

func (f UintFlag) IsPersistent() bool

IsPersistent specify whether the flag is persistent

Jump to

Keyboard shortcuts

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