flag

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package flag is used to wrap some APIs from go stdlib flag

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args() []string

Args returns the non-flag command-line arguments.

func Bool

func Bool(name string, value bool, usage string, options ...Option) *bool

Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.

func BoolVar

func BoolVar(p *bool, name string, value bool, usage string, options ...Option)

BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag.

func Duration

func Duration(name string, value time.Duration, usage string, options ...Option) *time.Duration

Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag. The flag accepts a value acceptable to time.ParseDuration.

func DurationVar

func DurationVar(p *time.Duration, name string, value time.Duration, usage string, options ...Option)

DurationVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag. The flag accepts a value acceptable to time.ParseDuration.

func Float32 added in v1.1.5

func Float32(name string, value float32, usage string, options ...Option) *float32

Float32 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.

func Float32Var added in v1.1.5

func Float32Var(p *float32, name string, value float32, usage string, options ...Option)

Float32Var defines a float32 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.

func Float64

func Float64(name string, value float64, usage string, options ...Option) *float64

Float64 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.

func Float64Var

func Float64Var(p *float64, name string, value float64, usage string, options ...Option)

Float64Var defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.

func Int

func Int(name string, value int, usage string, options ...Option) *int

Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag.

func Int64

func Int64(name string, value int64, usage string, options ...Option) *int64

Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag.

func Int64Var

func Int64Var(p *int64, name string, value int64, usage string, options ...Option)

Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag.

func IntSlice added in v1.0.6

func IntSlice(name string, value []int, usage string, options ...Option) *[]int

IntSlice defines a int slice flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.

func IntSliceVar added in v1.0.6

func IntSliceVar(p *[]int, name string, value []int, usage string, options ...Option)

IntSliceVar defines a int slice flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.

func IntVar

func IntVar(p *int, name string, value int, usage string, options ...Option)

IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag.

func NArg added in v1.6.11

func NArg() int

NArg returns the count of non-flag command-line arguments.

func Parse

func Parse()

Parse parses the command-line flags from os.Args[1:]. Must be called after all flags are defined and before flags are accessed by the program.

func Parsed

func Parsed() bool

Parsed reports whether the command-line flags have been parsed.

func String

func String(name string, value string, usage string, options ...Option) *string

String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.

func StringSlice added in v1.0.6

func StringSlice(name string, value []string, usage string, options ...Option) *[]string

StringSlice defines a string slice flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.

func StringSliceVar added in v1.0.6

func StringSliceVar(p *[]string, name string, value []string, usage string, options ...Option)

StringSliceVar defines a string slice flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.

func StringVar

func StringVar(p *string, name string, value string, usage string, options ...Option)

StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.

func TreatAsLongOpt

func TreatAsLongOpt(b bool) bool

TreatAsLongOpt treat name as long option name or short.

func Uint

func Uint(name string, value uint, usage string, options ...Option) *uint

Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.

func Uint64

func Uint64(name string, value uint64, usage string, options ...Option) *uint64

Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag.

func Uint64Var

func Uint64Var(p *uint64, name string, value uint64, usage string, options ...Option)

Uint64Var defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag.

func UintVar

func UintVar(p *uint, name string, value uint, usage string, options ...Option)

UintVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.

Types

type Option

type Option func(flag cmdr.OptFlag)

Option is used by cmdr fluent API and flag compatible API

func WithAction

func WithAction(action func(cmd *cmdr.Command, args []string) (err error)) (opt Option)

WithAction to specify the action as the option was matched

func WithAliases

func WithAliases(aliases ...string) (opt Option)

WithAliases sets the aliases string list

func WithCommand added in v1.0.5

func WithCommand(cmdDefines func(newSubCmd cmdr.OptCmd)) (opt Option)

WithCommand define an (Sub-)Command

func WithDefaultValue

func WithDefaultValue(val interface{}, placeholder string) (opt Option)

WithDefaultValue set the value with explicit data type, and its placeholder name.

func WithDeprecated

func WithDeprecated(deprecation string) (opt Option)

WithDeprecated sets a version string for an deprecation option

func WithDescription

func WithDescription(oneLine, long string) (opt Option)

WithDescription sets the description string

func WithEnvKeys added in v1.6.21

func WithEnvKeys(keys ...string) (opt Option)

WithEnvKeys binds the environ variable keynames to an option.

func WithExamples

func WithExamples(examples string) (opt Option)

WithExamples sets the example string for an option

func WithExternalTool

func WithExternalTool(envKeyName string) (opt Option)

WithExternalTool allows launch an external program via an environment key yours specified. for example, while you setup by `WithExternalTool("EDITOR")`, cmdr will lookup it from os environment and launch that program. for EDITOR=vim, `vim` will be launched.

func WithGroup

func WithGroup(group string) (opt Option)

WithGroup sets the group name

func WithHeadLike

func WithHeadLike(enable bool, min, max int64) (opt Option)

WithHeadLike enables `head -n` mode. min, max will be ignored at this version, its might be impl in the future

func WithHidden

func WithHidden(hidden bool) (opt Option)

WithHidden sets an hidden option that does not be displayed in any list or help screen.

func WithLong

func WithLong(long string) (opt Option)

WithLong sets the Long/Full title

func WithOnSet added in v1.6.21

func WithOnSet(f func(keyPath string, value interface{})) (opt Option)

WithOnSet binds the OnSet handler to an option.

func WithShort

func WithShort(short string) (opt Option)

WithShort sets the short title

func WithTitles

func WithTitles(short, long string, aliases ...string) (opt Option)

WithTitles setup short title, long title, and aliases titles

func WithToggleGroup

func WithToggleGroup(group string) (opt Option)

WithToggleGroup allows to specify an group name, and any options in this group will be treated as an toggleable group, just like raido button group.

func WithValidArgs

func WithValidArgs(list ...string) (opt Option)

WithValidArgs enables enumerable values for an option.

Jump to

Keyboard shortcuts

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