zflag

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: BSD-3-Clause Imports: 16 Imported by: 4

README

zflag

This is a fork of zulucmd/zflag, which is a fork of cornfeedhobo/pflag, which in turn is a fork of spf13/pflag. All forks were created due to poor maintenance. This is madness.

GoDoc Go Report Card GitHub release (latest SemVer) Build Status

Installation

zflag is available using the standard go get command.

Install by running:

go get github.com/stefansundin/go-zflag

You can import the package with the flag name using:

import (
	flag "github.com/stefansundin/go-zflag"
)

Supported Syntax

--flag    // boolean flags, or flags with no option default values
--flag x  // only on flags without a default value
--flag=x

Unlike the flag package, a single dash before an option means something different than a double dash. Single dashes signify a series of shorthand letters for flags. All but the last shorthand letter must be boolean flags or a flag with a default value

// boolean or flags where the 'no option default value' is set
-f
-f=true
-abc
but
-b true is INVALID

// non-boolean and flags without a 'no option default value'
-n 1234
-n=1234
-n1234

// mixed
-abcs "hello"
-absd="hello"
-abcs1234

Slice flags can be specified multiple times, or specified with an equal sign and csv.

--sliceVal one --sliceVal=two
--sliceVal=one,two

Integer flags accept 1234, 0664, 0x1234 and may be negative. Boolean flags (in their long form) accept 1, 0, t, f, true, false, TRUE, FALSE, True, False. Duration flags accept any input valid for time.ParseDuration.

Flag parsing stops after the terminator --. Unlike the flag package, flags can be interspersed with arguments anywhere on the command line before this terminator.

Documentation

You can see the full reference documentation of the zflag package at godoc.org, querying with go doc, or through go's standard documentation system by running godoc -http=:6060 and browsing to http://localhost:6060/pkg/github.com/stefansundin/go-zflag after installation.

Create a flag set

The default set of command-line flags is controlled by top-level functions. The FlagSet type allows one to define independent sets of flags, such as to implement subcommands in a command-line interface. The methods of FlagSet are analogous to the top-level functions for the command-line flag set.

flagSet := flag.NewFlagSet("myapp", flag.ExitOnError)
Set a custom default for flags passed without values

If a flag has a NoOptDefVal and the flag is set on the command line without an option, the flag will be set to the NoOptDefVal.

Example:

var ip = flag.Int("flagname", 1234, "help message", flag.OptShorthand('f'), flag.OptNoOptDefVal("4321"))

Results:

Parsed Arguments Resulting Value
--flagname=1357 ip=1357
--flagname ip=4321
[nothing] ip=1234
Mutating or "Normalizing" Flag names

It is possible to set a custom flag name 'normalization function.' It allows flag names to be mutated both when created in the code and when used on the command line to some 'normalized' form. The 'normalized' form is used for comparison. Two examples of using the custom normalization func follow.

Example #1: You want -, _, and . in flags to compare the same, i.e. --my-flag == --my_flag == --my.flag

func wordSepNormalizeFunc(f *flag.FlagSet, name string) flag.NormalizedName {
	from := []string{"-", "_"}
	to := "."
	for _, sep := range from {
		name = strings.Replace(name, sep, to, -1)
	}
	return flag.NormalizedName(name)
}

flagSet.SetNormalizeFunc(wordSepNormalizeFunc)

Example #2: You want to alias two flags, i.e. --old-flag-name == --new-flag-name

func aliasNormalizeFunc(f *flag.FlagSet, name string) flag.NormalizedName {
	switch name {
	case "old-flag-name":
		name = "new-flag-name"
		break
	}
	return flag.NormalizedName(name)
}

flagSet.SetNormalizeFunc(aliasNormalizeFunc)
Deprecating a flag or its shorthand

It is possible to deprecate a flag, or just its shorthand. Deprecating a flag/shorthand hides it from help text and prints a usage message when the deprecated flag/shorthand is used.

Example #1: You want to deprecate a flag named "badflag" as well as inform the users what flag they should use instead.

// deprecate a flag by specifying its name and a usage message
flag.Bool("badflag", false, "this does something", flag.OptDeprecated("please use --good-flag instead"))

This hides "badflag" from help text, and prints Flag --badflag has been deprecated, please use --good-flag instead when "badflag" is used.

Example #2: You want to keep a flag name "noshorthandflag" but deprecate it's shortname "n".

// deprecate a flag shorthand by specifying its flag name and a usage message
flag.Bool("noshorthandflag", false, "this does something", flag.OptShorthand('n'), flag.OptShorthandDeprecated("please use --noshorthandflag only"))

This hides the shortname "n" from help text, and prints Flag shorthand -n has been deprecated, please use --noshorthandflag only when the shorthand n is used.

Note that usage message is essential here, and it should not be empty. If it is empty, it will panic at runtime.

Hidden flags

It is possible to mark a flag as hidden, meaning it will still function as normal, however will not show up in usage/help text.

Example: You have a flag named secretFlag that you need for internal use only and don't want it showing up in help text, or for its usage text to be available.

// hide a flag by specifying its name
flag.Bool("secretFlag", false, "this does something", flag.OptHidden())
Disable sorting of flags

It is possible to disable sorting of flags for help and usage message.

Example:

flag.Bool("verbose", false, "verbose output", flag.OptShorthand('v'))
flag.String("coolflag", "yeaah", "it's really cool flag")
flag.Int("usefulflag", 777, "sometimes it's very useful")
flag.SortFlags = false
flag.PrintDefaults()

Output:

  -v, --verbose           verbose output
      --coolflag string   it's really cool flag (default "yeaah")
      --usefulflag int    sometimes it's very useful (default 777)
Supporting Go flags when using zflag

In order to support flags defined using Go's flag package, they must be added to the zflag flagset. This is usually necessary to support flags defined by third-party dependencies (e.g. golang/glog).

Example: You want to add the Go flags to the CommandLine flagset

import (
	goflag "flag"
	flag "github.com/stefansundin/go-zflag"
)

var ip *int = flag.Int("flagname", 1234, "help message for flagname")

func main() {
	flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
	flag.Parse()
}
Shorthand flags

A flag supporting both long and short formats can be created with the new OptShorthand argument:

flag.Bool("toggle", false, "toggle help message", flag.OptShorthand('t'))
Shorthand-only flags

A shorthand-only flag can be created with OptShorthandOnly:

flag.String("value", "", "value help message", flag.OptShorthandOnly('l'))

This flag can be looked up using its long name, but will only be parsed when the short form is passed.

Unknown flags

Normally zflag will error when an unknown flag is passed, but it's also possible to disable that using FlagSet.ParseErrorsAllowlist.UnknownFlags:

flagSet.ParseErrorsAllowlist.UnknownFlags = true
flag.Parse()

These can then be obtained as a slice of strings using FlagSet.GetUnknownFlags().

Custom flag types in usage

There are two methods to set a custom type to be printed in the usage.

First, it's possible to set explicitly with UsageType:

flag.String("character", "", "character name", flag.OptUsageType("enum"))

Output:

  --character enum   character name (default "")

Alternatively, it's possible to include backticks around a single word in the usage string, which will be extracted and printed with the usage:

flag.String("character", "", "`character` name")

Output:

  --character character   character name (default "")

Note: This unquoting behavior can be disabled with Flag.DisableUnquoteUsage, or flag.OptDisableUnquoteUsage.

Customizing flag usages

You can customize the flag usages by overriding the FlagSet.FlagUsageFormatter field with a struct that implements FlagUsageFormatter. You can re-implement the whole interface or embed the DefaultFlagUsageFormatter to only re-implement some some functions.

For example:

type myFlagFormatter struct {
  flag.DefaultFlagUsageFormatter
}

func (f myFlagFormatter) Name(flag *flag.Flag) string {
  return "--not-hello"
}


flagSet := flag.NewFlagSet("myapp", flag.ExitOnError)
flagSet.String("hello", "", "myusage")

flagSet.FlagUsageFormatter = myFlagFormatter{}
flagSet.PrintDefaults()

Which will print:

--not-hello string   myusage
Disable printing a flag's default value

The printing of a flag's default value can be suppressed with Flag.DisablePrintDefault.

Example:

flag.Int("in", -1, "help message", flag.OptDisablePrintDefault(true))

Output:

  --in int   help message
Disable built-in help flags

Normally zflag will handle --help and -h when the flags aren't explicitly defined.

If for some reason there is a need to capture the error returned in this condition, it is possible to disable this built-in handling.

flagSet.DisableBuiltinHelp = true

Documentation

Overview

Package zflag is a drop-in replacement of Go's native flag package, implementing POSIX/GNU-style --flags. zflag is compatible with the GNU extensions to the POSIX recommendations for command-line options. See http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

zflag is available under the same style of BSD license as the Go language, which can be found in the LICENSE file.

If you import zflag under the name "flag" then all code should continue to function with no changes.

import flag "github.com/stefansundin/go-zflag"

There is one exception to this: if you directly instantiate the Flag struct there is one more field "Shorthand" that you will need to set. Most code never instantiates this struct directly, and instead uses functions such as String(), BoolVar(), and Var(), and is therefore unaffected.

Define flags using flag.String(), Bool(), Int(), etc.

This declares an integer flag, -flagname, stored in the pointer ip, with type *int.

var ip = flag.Int("flagname", 1234, "help message for flagname")

If you like, you can bind the flag to a variable using the Var() functions.

var flagvar int
func init() {
	flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
}

Or you can create custom flags that satisfy the Value interface (with pointer receivers) and couple them to flag parsing by

flag.Var(&flagVal, "name", "help message for flagname")

For such flags, the default value is just the initial value of the variable.

After all flags are defined, call

flag.Parse()

to parse the command line into the defined flags.

Flags may then be used directly. If you're using the flags themselves, they are all pointers; if you bind to variables, they're values.

fmt.Println("ip has value ", *ip)
fmt.Println("flagvar has value ", flagvar)

After parsing, the arguments after the flag are available as the slice flag.Args() or individually as flag.Arg(i). The arguments are indexed from 0 through flag.NArg()-1.

The zflag package also defines some new arguments that are not in flag, that give one-letter shorthands for flags.

var ip = flag.Int("flagname", 1234, "help message", flag.OptShorthand('f'))
var flagvar bool
func init() {
	flag.BoolVar(&flagvar, "boolname", true, "help message", flag.OptShorthand('b'))
}
flag.Var(&flagval, "varname", "help message", flag.OptShorthand('v'))

Shorthand letters can be used with single dashes on the command line. Boolean shorthand flags can be combined with other shorthand flags.

Command line flag syntax:

--flag    // boolean flags only
--flag=x

Unlike the flag package, a single dash before an option means something different than a double dash. Single dashes signify a series of shorthand letters for flags. All but the last shorthand letter must be boolean flags.

// boolean flags
-f
-abc
// non-boolean flags
-n 1234
-Ifile
// mixed
-abcs "hello"
-abcn1234

Flag parsing stops after the terminator "--". Unlike the flag package, flags can be interspersed with arguments anywhere on the command line before this terminator.

Integer flags accept 1234, 0664, 0x1234 and may be negative. Boolean flags (in their long form) accept 1, 0, t, f, true, false, TRUE, FALSE, True, False. Duration flags accept any input valid for time.ParseDuration.

The default set of command-line flags is controlled by top-level functions. The FlagSet type allows one to define independent sets of flags, such as to implement subcommands in a command-line interface. The methods of FlagSet are analogous to the top-level functions for the command-line flag set.

Index

Examples

Constants

This section is empty.

Variables

View Source
var CommandLine = NewFlagSet(os.Args[0], ExitOnError)

CommandLine is the default set of command-line flags, parsed from os.Args.

View Source
var ErrHelp = errors.New("zflag: help requested")

ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.

View Source
var Usage = func() {
	fmt.Fprintf(CommandLine.Output(), "Usage of %s:\n", os.Args[0])
	PrintDefaults()
}

Usage prints to standard error a usage message documenting all defined command-line flags. The function is a variable that may be changed to point to a custom function. By default it prints a simple header and calls PrintDefaults; for details about the format of the output and how to control it, see the documentation for PrintDefaults.

Functions

func Arg

func Arg(i int) string

Arg returns the i'th command-line argument. Arg(0) is the first remaining argument after flags have been processed.

func Args

func Args() []string

Args returns the non-flag command-line arguments.

func Bool

func Bool(name string, value bool, usage string, opts ...Opt) *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 BoolSlice

func BoolSlice(name string, value []bool, usage string, opts ...Opt) *[]bool

BoolSlice 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 BoolSliceVar

func BoolSliceVar(p *[]bool, name string, value []bool, usage string, opts ...Opt)

BoolSliceVar 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 BoolVar

func BoolVar(p *bool, name string, value bool, usage string, opts ...Opt)

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 BytesBase64

func BytesBase64(name string, value []byte, usage string, opts ...Opt) *[]byte

BytesBase64 defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.

func BytesBase64Var

func BytesBase64Var(p *[]byte, name string, value []byte, usage string, opts ...Opt)

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

func BytesHex

func BytesHex(name string, value []byte, usage string, opts ...Opt) *[]byte

BytesHex defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.

func BytesHexVar

func BytesHexVar(p *[]byte, name string, value []byte, usage string, opts ...Opt)

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

func Complex128

func Complex128(name string, value complex128, usage string, opts ...Opt) *complex128

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

func Complex128Slice

func Complex128Slice(name string, value []complex128, usage string, opts ...Opt) *[]complex128

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

func Complex128SliceVar

func Complex128SliceVar(p *[]complex128, name string, value []complex128, usage string, opts ...Opt)

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

func Complex128Var

func Complex128Var(p *complex128, name string, value complex128, usage string, opts ...Opt)

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

func Count

func Count(name string, usage string, opts ...Opt) *int

Count defines a count flag with specified name, and usage string. The return value is the address of an int variable that stores the value of the flag. A count flag will add 1 to its value every time it is found on the command line

func CountVar

func CountVar(p *int, name string, usage string, opts ...Opt)

CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set

func Duration

func Duration(name string, value time.Duration, usage string, opts ...Opt) *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.

func DurationSlice

func DurationSlice(name string, value []time.Duration, usage string, opts ...Opt) *[]time.Duration

DurationSlice 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.

func DurationSliceVar

func DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string, opts ...Opt)

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

func DurationVar

func DurationVar(p *time.Duration, name string, value time.Duration, usage string, opts ...Opt)

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.

func Float32

func Float32(name string, value float32, usage string, opts ...Opt) *float32

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

func Float32Slice

func Float32Slice(name string, value []float32, usage string, opts ...Opt) *[]float32

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

func Float32SliceVar

func Float32SliceVar(p *[]float32, name string, value []float32, usage string, opts ...Opt)

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

func Float32Var

func Float32Var(p *float32, name string, value float32, usage string, opts ...Opt)

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

func Float64

func Float64(name string, value float64, usage string, opts ...Opt) *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 Float64Slice

func Float64Slice(name string, value []float64, usage string, opts ...Opt) *[]float64

Float64Slice 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 Float64SliceVar

func Float64SliceVar(p *[]float64, name string, value []float64, usage string, opts ...Opt)

Float64SliceVar 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 Float64Var

func Float64Var(p *float64, name string, value float64, usage string, opts ...Opt)

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 Get

func Get(name string) (interface{}, error)

Get returns the value of the named flag.

func GetUnknownFlags

func GetUnknownFlags() []string

GetUnknownFlags returns unknown command-line flags in the order they were Parsed. This requires ParseErrorsWhitelist.UnknownFlags to be set so that parsing does not abort on the first unknown flag.

func IP

func IP(name string, value net.IP, usage string, opts ...Opt) *net.IP

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

func IPMask

func IPMask(name string, value net.IPMask, usage string, opts ...Opt) *net.IPMask

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

func IPMaskVar

func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string, opts ...Opt)

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

func IPNet

func IPNet(name string, value net.IPNet, usage string, opts ...Opt) *net.IPNet

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

func IPNetSlice

func IPNetSlice(name string, value []net.IPNet, usage string, opts ...Opt) *[]net.IPNet

IPNetSlice defines a []net.IPNet flag with specified name, default value, and usage string. The return value is the address of a []net.IPNet variable that stores the value of the flag.

func IPNetSliceVar

func IPNetSliceVar(p *[]net.IPNet, name string, value []net.IPNet, usage string, opts ...Opt)

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

func IPNetVar

func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string, opts ...Opt)

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

func IPSlice

func IPSlice(name string, value []net.IP, usage string, opts ...Opt) *[]net.IP

IPSlice defines a []net.IP flag with specified name, default value, and usage string. The return value is the address of a []net.IP variable that stores the value of the flag.

func IPSliceVar

func IPSliceVar(p *[]net.IP, name string, value []net.IP, usage string, opts ...Opt)

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

func IPVar

func IPVar(p *net.IP, name string, value net.IP, usage string, opts ...Opt)

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

func Int

func Int(name string, value int, usage string, opts ...Opt) *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 Int16

func Int16(name string, value int16, usage string, opts ...Opt) *int16

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

func Int16Slice

func Int16Slice(name string, value []int16, usage string, opts ...Opt) *[]int16

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

func Int16SliceVar

func Int16SliceVar(p *[]int16, name string, value []int16, usage string, opts ...Opt)

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

func Int16Var

func Int16Var(p *int16, name string, value int16, usage string, opts ...Opt)

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

func Int32

func Int32(name string, value int32, usage string, opts ...Opt) *int32

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

func Int32Slice

func Int32Slice(name string, value []int32, usage string, opts ...Opt) *[]int32

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

func Int32SliceVar

func Int32SliceVar(p *[]int32, name string, value []int32, usage string, opts ...Opt)

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

func Int32Var

func Int32Var(p *int32, name string, value int32, usage string, opts ...Opt)

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

func Int64

func Int64(name string, value int64, usage string, opts ...Opt) *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 Int64Slice

func Int64Slice(name string, value []int64, usage string, opts ...Opt) *[]int64

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

func Int64SliceVar

func Int64SliceVar(p *[]int64, name string, value []int64, usage string, opts ...Opt)

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

func Int64Var

func Int64Var(p *int64, name string, value int64, usage string, opts ...Opt)

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 Int8

func Int8(name string, value int8, usage string, opts ...Opt) *int8

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

func Int8Slice

func Int8Slice(name string, value []int8, usage string, opts ...Opt) *[]int8

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

func Int8SliceVar

func Int8SliceVar(p *[]int8, name string, value []int8, usage string, opts ...Opt)

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

func Int8Var

func Int8Var(p *int8, name string, value int8, usage string, opts ...Opt)

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

func IntSlice

func IntSlice(name string, value []int, usage string, opts ...Opt) *[]int

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

func IntSliceVar

func IntSliceVar(p *[]int, name string, value []int, usage string, opts ...Opt)

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

func IntVar

func IntVar(p *int, name string, value int, usage string, opts ...Opt)

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

func NArg() int

NArg is the number of arguments remaining after flags have been processed.

func NFlag

func NFlag() int

NFlag returns the number of command-line flags that have been set.

func NewUnknownFlagError

func NewUnknownFlagError(name string) error

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 ParseAll

func ParseAll(fn func(flag *Flag, value string) error)

ParseAll parses the command-line flags from os.Args[1:] and called fn for each. The arguments for fn are flag and value. Must be called after all flags are defined and before flags are accessed by the program.

func ParseIPv4Mask

func ParseIPv4Mask(s string) net.IPMask

ParseIPv4Mask written in IP form (e.g. 255.255.255.0). This function should really belong to the net package.

func Parsed

func Parsed() bool

Parsed returns true if the command-line flags have been parsed.

func PrintDefaults

func PrintDefaults()

PrintDefaults prints, to standard error unless configured otherwise, a usage message showing the default settings of all defined command-line flags. For an integer valued flag x, the default output has the form

-x int
	usage-message-for-x (default 7)

The usage message will appear on a separate line for anything but a bool flag with a one-byte name. For bool flags, the type is omitted and if the flag name is one byte the usage message appears on the same line. The parenthetical default is omitted if the default is the zero value for the type. The listed type, here int, can be changed by placing a back-quoted name in the flag's usage string; the first such item in the message is taken to be a parameter name to show in the message and the back quotes are stripped from the message when displayed. For instance, given

flag.String("I", "", "search `directory` for include files")

the output will be

-I directory
	search directory for include files.

To change the destination for flag messages, call CommandLine.SetOutput.

func Set

func Set(name, value string) error

Set sets the value of the named command-line flag.

func SetInterspersed

func SetInterspersed(interspersed bool)

SetInterspersed sets whether to support interspersed option/non-option arguments.

func String

func String(name string, value string, usage string, opts ...Opt) *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 StringArray

func StringArray(name string, value []string, usage string, opts ...Opt) *[]string

StringArray 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. Compared to StringSlice flags, a StringArray will not be split on commas.

func StringArrayVar

func StringArrayVar(p *[]string, name string, value []string, usage string, opts ...Opt)

StringArrayVar 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. Compared to StringSlice flags, a StringArray will not be split on commas.

func StringSlice

func StringSlice(name string, value []string, usage string, opts ...Opt) *[]string

StringSlice 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. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:

--ss="v1,v2" --ss="v3"

will result in

[]string{"v1", "v2", "v3"}

func StringSliceVar

func StringSliceVar(p *[]string, name string, value []string, usage string, opts ...Opt)

StringSliceVar 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. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:

--ss="v1,v2" --ss="v3"

will result in

[]string{"v1", "v2", "v3"}

func StringToInt

func StringToInt(name string, value map[string]int, usage string, opts ...Opt) *map[string]int

StringToInt defines a map[string]int flag with specified name, default value, and usage string. The return value is the address of a map[string]int variable that stores the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func StringToInt64

func StringToInt64(name string, value map[string]int64, usage string, opts ...Opt) *map[string]int64

StringToInt64 defines a map[string]int64 flag with specified name, default value, and usage string. The return value is the address of a map[string]int64 variable that stores the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func StringToInt64Var

func StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string, opts ...Opt)

StringToInt64Var defines a map[string]int64 flag with specified name, default value, and usage string. The argument p points to a map[string]int64 variable in which to store the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func StringToIntVar

func StringToIntVar(p *map[string]int, name string, value map[string]int, usage string, opts ...Opt)

StringToIntVar defines a map[string]int flag with specified name, default value, and usage string. The argument p points to a map[string]int variable in which to store the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func StringToString

func StringToString(name string, value map[string]string, usage string, opts ...Opt) *map[string]string

StringToString defines a map[string]string flag with specified name, default value, and usage string. The return value is the address of a map[string]string variable that stores the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func StringToStringVar

func StringToStringVar(p *map[string]string, name string, value map[string]string, usage string, opts ...Opt)

StringToStringVar defines a map[string]string flag with specified name, default value, and usage string. The argument p points to a map[string]string variable in which to store the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func StringVar

func StringVar(p *string, name string, value string, usage string, opts ...Opt)

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 Uint

func Uint(name string, value uint, usage string, opts ...Opt) *uint

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

func Uint16

func Uint16(name string, value uint16, usage string, opts ...Opt) *uint16

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

func Uint16Slice

func Uint16Slice(name string, value []uint16, usage string, opts ...Opt) *[]uint16

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

func Uint16SliceVar

func Uint16SliceVar(p *[]uint16, name string, value []uint16, usage string, opts ...Opt)

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

func Uint16Var

func Uint16Var(p *uint16, name string, value uint16, usage string, opts ...Opt)

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

func Uint32

func Uint32(name string, value uint32, usage string, opts ...Opt) *uint32

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

func Uint32Slice

func Uint32Slice(name string, value []uint32, usage string, opts ...Opt) *[]uint32

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

func Uint32SliceVar

func Uint32SliceVar(p *[]uint32, name string, value []uint32, usage string, opts ...Opt)

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

func Uint32Var

func Uint32Var(p *uint32, name string, value uint32, usage string, opts ...Opt)

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

func Uint64

func Uint64(name string, value uint64, usage string, opts ...Opt) *uint64

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

func Uint64Slice

func Uint64Slice(name string, value []uint64, usage string, opts ...Opt) *[]uint64

Uint64Slice 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 Uint64SliceVar

func Uint64SliceVar(p *[]uint64, name string, value []uint64, usage string, opts ...Opt)

Uint64SliceVar 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 Uint64Var

func Uint64Var(p *uint64, name string, value uint64, usage string, opts ...Opt)

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

func Uint8

func Uint8(name string, value uint8, usage string, opts ...Opt) *uint8

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

func Uint8Slice

func Uint8Slice(name string, value []uint8, usage string, opts ...Opt) *[]uint8

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

func Uint8SliceVar

func Uint8SliceVar(p *[]uint8, name string, value []uint8, usage string, opts ...Opt)

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

func Uint8Var

func Uint8Var(p *uint8, name string, value uint8, usage string, opts ...Opt)

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

func UintSlice

func UintSlice(name string, value []uint, usage string, opts ...Opt) *[]uint

UintSlice 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 UintSliceVar

func UintSliceVar(p *[]uint, name string, value []uint, usage string, opts ...Opt)

UintSliceVar 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.

func UintVar

func UintVar(p *uint, name string, value uint, usage string, opts ...Opt)

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

func UnquoteUsage

func UnquoteUsage(flag *Flag) (name string, usage string)

UnquoteUsage extracts a back-quoted name from the usage string for a flag and returns it and the un-quoted usage. Given "a `name` to show" it returns ("name", "a name to show"). If there are no back quotes, the name is an educated guess of the type of the flag's value, or the empty string if the flag is boolean.

func Visit

func Visit(fn func(*Flag))

Visit visits the command-line flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits only those flags that have been set.

func VisitAll

func VisitAll(fn func(*Flag))

VisitAll visits the command-line flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits all flags, even those not set.

Types

type ApplyOptFunc

type ApplyOptFunc func(c *Flag) error

type DefaultFlagUsageFormatter

type DefaultFlagUsageFormatter struct{}

func (DefaultFlagUsageFormatter) DefaultValue

func (d DefaultFlagUsageFormatter) DefaultValue(flag *Flag) string

func (DefaultFlagUsageFormatter) Deprecated

func (d DefaultFlagUsageFormatter) Deprecated(flag *Flag) string

func (DefaultFlagUsageFormatter) Name

func (d DefaultFlagUsageFormatter) Name(flag *Flag) string

func (DefaultFlagUsageFormatter) NoOptDefValue

func (d DefaultFlagUsageFormatter) NoOptDefValue(flag *Flag) string

func (DefaultFlagUsageFormatter) Usage

func (d DefaultFlagUsageFormatter) Usage(flag *Flag, s string) string

func (DefaultFlagUsageFormatter) UsageVarName

func (d DefaultFlagUsageFormatter) UsageVarName(flag *Flag, s string) string

type ErrorHandling

type ErrorHandling int

ErrorHandling defines how to handle flag parsing errors.

const (
	// ContinueOnError will return an err from Parse() if an error is found
	ContinueOnError ErrorHandling = iota
	// ExitOnError will call os.Exit(2) if an error is found when parsing
	ExitOnError
	// PanicOnError will panic() if an error is found when parsing flags
	PanicOnError
)

type Flag

type Flag struct {
	Name                string              // name as it appears on command line
	Shorthand           rune                // one-letter abbreviated flag
	ShorthandOnly       bool                // If the user set only the shorthand
	Usage               string              // help message
	UsageType           string              // flag type displayed in the help message
	DisableUnquoteUsage bool                // toggle unquoting and extraction of type from usage
	DisablePrintDefault bool                // toggle printing of the default value in usage message
	Value               Value               // value as set
	DefValue            string              // default value (as text); for usage message
	Changed             bool                // If the user set the value (or if left to default)
	NoOptDefVal         string              // default value (as text); if the flag is on the command line without any options
	Deprecated          string              // If this flag is deprecated, this string is the new or now thing to use
	Hidden              bool                // used by zulu.Command to allow flags to be hidden from help/usage text
	ShorthandDeprecated string              // If the shorthand of this flag is deprecated, this string is the new or now thing to use
	Group               string              // flag group
	Annotations         map[string][]string // Use it to annotate this specific flag for your application; used by zulu.Command bash completion code
}

A Flag represents the state of a flag.

func GetAllFlags

func GetAllFlags() []*Flag

GetAllFlags return the flags in lexicographical order or in primordial order if f.SortFlags is false.

func GetFlags

func GetFlags() []*Flag

GetFlags return the flags in lexicographical order or in primordial order if f.SortFlags is false.

func Lookup

func Lookup(name string) *Flag

Lookup returns the Flag structure of the named command-line flag, returning nil if none exists.

func ShorthandLookup

func ShorthandLookup(name rune) *Flag

ShorthandLookup returns the Flag structure of the shorthand flag, returning nil if none exists.

Example
name := "verbose"
short := 'v'

Bool(name, false, "verbose output", OptShorthand(short))

// len(short) must be == 1
flag := ShorthandLookup(short)

fmt.Println(flag.Name)
Output:

func ShorthandLookupStr

func ShorthandLookupStr(name string) *Flag

ShorthandLookupStr is the same as ShorthandLookup, but you can look it up through a string. It panics if name contains more than one UTF-8 character.

func Var

func Var(value Value, name, usage string, opts ...Opt) *Flag

Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.

func ZFlagFromGoFlag

func ZFlagFromGoFlag(goflag *goflag.Flag) *Flag

ZFlagFromGoFlag will return a *zflag.Flag given a *flag.Flag If the *flag.Flag.Name was a single character (ex: `v`) it will be accessible with both `-v` and `--v` in flags. If the golang flag was more than a single character (ex: `verbose`) it will only be accessible via `--verbose`

func (*Flag) SetAnnotation

func (f *Flag) SetAnnotation(key string, values []string) error

SetAnnotation allows one to set arbitrary annotations on this flag. This is sometimes used by gowarden/zulu programs which want to generate additional bash completion information.

type FlagSet

type FlagSet struct {
	// Usage is the function called when an error occurs while parsing flags.
	// The field is a function (not a method) that may be changed to point to
	// a custom error handler.
	Usage func()

	// SortFlags is used to indicate, if user wants to have sorted flags in
	// help/usage messages.
	SortFlags bool

	// ParseErrorsAllowlist is used to configure an allowlist of errors
	ParseErrorsAllowlist ParseErrorsAllowlist

	// DisableBuiltinHelp toggles the built-in convention of handling -h and --help
	DisableBuiltinHelp bool

	// FlagUsageFormatter allows for custom formatting of flag usage output.
	// Each individual item needs to be implemented. See FlagUsagesForGroupWrapped for info on what gets passed.
	FlagUsageFormatter FlagUsageFormatter
	// contains filtered or unexported fields
}

A FlagSet represents a set of defined flags.

func NewFlagSet

func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet

NewFlagSet returns a new, empty flag set with the specified name, error handling property and SortFlags set to true.

func (*FlagSet) AddFlag

func (f *FlagSet) AddFlag(flag *Flag)

AddFlag will add the flag to the FlagSet

func (*FlagSet) AddFlagSet

func (f *FlagSet) AddFlagSet(newSet *FlagSet)

AddFlagSet adds one FlagSet to another. If a flag is already present in f the flag from newSet will be ignored.

func (*FlagSet) AddGoFlag

func (f *FlagSet) AddGoFlag(goflag *goflag.Flag)

AddGoFlag will add the given *flag.Flag to the zflag.FlagSet

func (*FlagSet) AddGoFlagSet

func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet)

AddGoFlagSet will add the given *flag.FlagSet to the zflag.FlagSet

func (*FlagSet) Arg

func (f *FlagSet) Arg(i int) string

Arg returns the i'th argument. Arg(0) is the first remaining argument after flags have been processed.

func (*FlagSet) Args

func (f *FlagSet) Args() []string

Args returns the non-flag arguments.

func (*FlagSet) ArgsLenAtDash

func (f *FlagSet) ArgsLenAtDash() int

ArgsLenAtDash will return the length of f.Args at the moment when a -- was found during arg parsing. This allows your program to know which args were before the -- and which came after.

func (*FlagSet) Bool

func (f *FlagSet) Bool(name string, value bool, usage string, opts ...Opt) *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 (*FlagSet) BoolSlice

func (f *FlagSet) BoolSlice(name string, value []bool, usage string, opts ...Opt) *[]bool

BoolSlice 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 (*FlagSet) BoolSliceVar

func (f *FlagSet) BoolSliceVar(p *[]bool, name string, value []bool, usage string, opts ...Opt)

BoolSliceVar defines a boolSlice 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 (*FlagSet) BoolVar

func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string, opts ...Opt)

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 (*FlagSet) BytesBase64

func (f *FlagSet) BytesBase64(name string, value []byte, usage string, opts ...Opt) *[]byte

BytesBase64 defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.

func (*FlagSet) BytesBase64Var

func (f *FlagSet) BytesBase64Var(p *[]byte, name string, value []byte, usage string, opts ...Opt)

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

func (*FlagSet) BytesHex

func (f *FlagSet) BytesHex(name string, value []byte, usage string, opts ...Opt) *[]byte

BytesHex defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.

func (*FlagSet) BytesHexVar

func (f *FlagSet) BytesHexVar(p *[]byte, name string, value []byte, usage string, opts ...Opt)

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

func (*FlagSet) Changed

func (f *FlagSet) Changed(name string) bool

Changed returns true if the flag was explicitly set during Parse() and false otherwise

func (*FlagSet) Complex128

func (f *FlagSet) Complex128(name string, value complex128, usage string, opts ...Opt) *complex128

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

func (*FlagSet) Complex128Slice

func (f *FlagSet) Complex128Slice(name string, value []complex128, usage string, opts ...Opt) *[]complex128

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

func (*FlagSet) Complex128SliceVar

func (f *FlagSet) Complex128SliceVar(p *[]complex128, name string, value []complex128, usage string, opts ...Opt)

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

func (*FlagSet) Complex128Var

func (f *FlagSet) Complex128Var(p *complex128, name string, value complex128, usage string, opts ...Opt)

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

func (*FlagSet) Count

func (f *FlagSet) Count(name string, usage string, opts ...Opt) *int

Count defines a count flag with specified name, and usage string. The return value is the address of an int variable that stores the value of the flag. A count flag will add 1 to its value every time it is found on the command line

func (*FlagSet) CountVar

func (f *FlagSet) CountVar(p *int, name string, usage string, opts ...Opt)

CountVar defines a count flag with specified name, and usage string. The argument p points to an int variable in which to store the value of the flag. A count flag will add 1 to its value every time it is found on the command line

func (*FlagSet) Duration

func (f *FlagSet) Duration(name string, value time.Duration, usage string, opts ...Opt) *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.

func (*FlagSet) DurationSlice

func (f *FlagSet) DurationSlice(name string, value []time.Duration, usage string, opts ...Opt) *[]time.Duration

DurationSlice 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.

func (*FlagSet) DurationSliceVar

func (f *FlagSet) DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string, opts ...Opt)

DurationSliceVar defines a durationSlice 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.

func (*FlagSet) DurationVar

func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string, opts ...Opt)

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.

func (*FlagSet) FlagUsages

func (f *FlagSet) FlagUsages() string

FlagUsages returns a string containing the usage information for all flags in the FlagSet

func (*FlagSet) FlagUsagesForGroup

func (f *FlagSet) FlagUsagesForGroup(group string) string

FlagUsagesForGroup returns a string containing the usage information for all flags in the FlagSet for group

func (*FlagSet) FlagUsagesForGroupWrapped

func (f *FlagSet) FlagUsagesForGroupWrapped(group string, cols int) string

FlagUsagesForGroupWrapped returns a string containing the usage information for all flags in the FlagSet for group. Wrapped to `cols` columns (0 for no wrapping)

func (*FlagSet) FlagUsagesWrapped

func (f *FlagSet) FlagUsagesWrapped(cols int) string

FlagUsagesWrapped returns a string containing the usage information for all flags in the FlagSet. Wrapped to `cols` columns (0 for no wrapping)

func (*FlagSet) Float32

func (f *FlagSet) Float32(name string, value float32, usage string, opts ...Opt) *float32

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

func (*FlagSet) Float32Slice

func (f *FlagSet) Float32Slice(name string, value []float32, usage string, opts ...Opt) *[]float32

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

func (*FlagSet) Float32SliceVar

func (f *FlagSet) Float32SliceVar(p *[]float32, name string, value []float32, usage string, opts ...Opt)

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

func (*FlagSet) Float32Var

func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string, opts ...Opt)

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

func (*FlagSet) Float64

func (f *FlagSet) Float64(name string, value float64, usage string, opts ...Opt) *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 (*FlagSet) Float64Slice

func (f *FlagSet) Float64Slice(name string, value []float64, usage string, opts ...Opt) *[]float64

Float64Slice 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 (*FlagSet) Float64SliceVar

func (f *FlagSet) Float64SliceVar(p *[]float64, name string, value []float64, usage string, opts ...Opt)

Float64SliceVar defines a float64Slice 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 (*FlagSet) Float64Var

func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string, opts ...Opt)

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 (*FlagSet) Get

func (f *FlagSet) Get(name string) (interface{}, error)

Get returns the value of the named flag.

func (*FlagSet) GetAllFlags

func (f *FlagSet) GetAllFlags() (flags []*Flag)

GetAllFlags return the flags in lexicographical order or in primordial order if f.SortFlags is false. It visits all flags, even those not set.

func (*FlagSet) GetBool

func (f *FlagSet) GetBool(name string) (bool, error)

GetBool return the bool value of a flag with the given name

func (*FlagSet) GetBoolSlice

func (f *FlagSet) GetBoolSlice(name string) ([]bool, error)

GetBoolSlice returns the []bool value of a flag with the given name.

func (*FlagSet) GetBytesBase64

func (f *FlagSet) GetBytesBase64(name string) ([]byte, error)

GetBytesBase64 return the []byte value of a flag with the given name

func (*FlagSet) GetBytesHex

func (f *FlagSet) GetBytesHex(name string) ([]byte, error)

GetBytesHex return the []byte value of a flag with the given name

func (*FlagSet) GetComplex128

func (f *FlagSet) GetComplex128(name string) (complex128, error)

GetComplex128 return the complex128 value of a flag with the given name

func (*FlagSet) GetComplex128Slice

func (f *FlagSet) GetComplex128Slice(name string) ([]complex128, error)

GetComplex128Slice return the []complex128 value of a flag with the given name

func (*FlagSet) GetCount

func (f *FlagSet) GetCount(name string) (int, error)

GetCount return the int value of a flag with the given name

func (*FlagSet) GetDuration

func (f *FlagSet) GetDuration(name string) (time.Duration, error)

GetDuration return the duration value of a flag with the given name

func (*FlagSet) GetDurationSlice

func (f *FlagSet) GetDurationSlice(name string) ([]time.Duration, error)

GetDurationSlice returns the []time.Duration value of a flag with the given name

func (*FlagSet) GetFlags

func (f *FlagSet) GetFlags() (flags []*Flag)

GetFlags return the flags in lexicographical order or in primordial order if f.SortFlags is false. It visits only those flags that have been set.

func (*FlagSet) GetFloat32

func (f *FlagSet) GetFloat32(name string) (float32, error)

GetFloat32 return the float32 value of a flag with the given name

func (*FlagSet) GetFloat32Slice

func (f *FlagSet) GetFloat32Slice(name string) ([]float32, error)

GetFloat32Slice return the []float32 value of a flag with the given name

func (*FlagSet) GetFloat64

func (f *FlagSet) GetFloat64(name string) (float64, error)

GetFloat64 return the float64 value of a flag with the given name

func (*FlagSet) GetFloat64Slice

func (f *FlagSet) GetFloat64Slice(name string) ([]float64, error)

GetFloat64Slice return the []float64 value of a flag with the given name

func (*FlagSet) GetIP

func (f *FlagSet) GetIP(name string) (net.IP, error)

GetIP return the net.IP value of a flag with the given name

func (*FlagSet) GetIPNet

func (f *FlagSet) GetIPNet(name string) (net.IPNet, error)

GetIPNet return the net.IPNet value of a flag with the given name

func (*FlagSet) GetIPNetSlice

func (f *FlagSet) GetIPNetSlice(name string) ([]net.IPNet, error)

GetIPNetSlice returns the []net.IPNet value of a flag with the given name

func (*FlagSet) GetIPSlice

func (f *FlagSet) GetIPSlice(name string) ([]net.IP, error)

GetIPSlice returns the []net.IP value of a flag with the given name

func (*FlagSet) GetIPv4Mask

func (f *FlagSet) GetIPv4Mask(name string) (net.IPMask, error)

GetIPv4Mask return the net.IPv4Mask value of a flag with the given name

func (*FlagSet) GetInt

func (f *FlagSet) GetInt(name string) (int, error)

GetInt return the int value of a flag with the given name

func (*FlagSet) GetInt16

func (f *FlagSet) GetInt16(name string) (int16, error)

GetInt16 returns the int16 value of a flag with the given name

func (*FlagSet) GetInt16Slice

func (f *FlagSet) GetInt16Slice(name string) ([]int16, error)

GetInt16Slice return the []int16 value of a flag with the given name

func (*FlagSet) GetInt32

func (f *FlagSet) GetInt32(name string) (int32, error)

GetInt32 return the int32 value of a flag with the given name

func (*FlagSet) GetInt32Slice

func (f *FlagSet) GetInt32Slice(name string) ([]int32, error)

GetInt32Slice return the []int32 value of a flag with the given name

func (*FlagSet) GetInt64

func (f *FlagSet) GetInt64(name string) (int64, error)

GetInt64 return the int64 value of a flag with the given name

func (*FlagSet) GetInt64Slice

func (f *FlagSet) GetInt64Slice(name string) ([]int64, error)

GetInt64Slice return the []int64 value of a flag with the given name

func (*FlagSet) GetInt8

func (f *FlagSet) GetInt8(name string) (int8, error)

GetInt8 return the int8 value of a flag with the given name

func (*FlagSet) GetInt8Slice

func (f *FlagSet) GetInt8Slice(name string) ([]int8, error)

GetInt8Slice return the []int8 value of a flag with the given name

func (*FlagSet) GetIntSlice

func (f *FlagSet) GetIntSlice(name string) ([]int, error)

GetIntSlice return the []int value of a flag with the given name

func (*FlagSet) GetNormalizeFunc

func (f *FlagSet) GetNormalizeFunc() func(f *FlagSet, name string) NormalizedName

GetNormalizeFunc returns the previously set NormalizeFunc of a function which does no translation, if not set previously.

func (*FlagSet) GetString

func (f *FlagSet) GetString(name string) (string, error)

GetString return the string value of a flag with the given name

func (*FlagSet) GetStringArray

func (f *FlagSet) GetStringArray(name string) ([]string, error)

GetStringArray return the []string value of a flag with the given name

func (*FlagSet) GetStringSlice

func (f *FlagSet) GetStringSlice(name string) ([]string, error)

GetStringSlice return the []string value of a flag with the given name

func (*FlagSet) GetStringToInt

func (f *FlagSet) GetStringToInt(name string) (map[string]int, error)

GetStringToInt return the map[string]int value of a flag with the given name

func (*FlagSet) GetStringToInt64

func (f *FlagSet) GetStringToInt64(name string) (map[string]int64, error)

GetStringToInt64 return the map[string]int64 value of a flag with the given name

func (*FlagSet) GetStringToString

func (f *FlagSet) GetStringToString(name string) (map[string]string, error)

GetStringToString return the map[string]string value of a flag with the given name

func (*FlagSet) GetUint

func (f *FlagSet) GetUint(name string) (uint, error)

GetUint return the uint value of a flag with the given name

func (*FlagSet) GetUint16

func (f *FlagSet) GetUint16(name string) (uint16, error)

GetUint16 return the uint16 value of a flag with the given name

func (*FlagSet) GetUint16Slice

func (f *FlagSet) GetUint16Slice(name string) ([]uint16, error)

GetUint16Slice return the []uint16 value of a flag with the given name

func (*FlagSet) GetUint32

func (f *FlagSet) GetUint32(name string) (uint32, error)

GetUint32 return the uint32 value of a flag with the given name

func (*FlagSet) GetUint32Slice

func (f *FlagSet) GetUint32Slice(name string) ([]uint32, error)

GetUint32Slice return the []uint32 value of a flag with the given name

func (*FlagSet) GetUint64

func (f *FlagSet) GetUint64(name string) (uint64, error)

GetUint64 return the uint64 value of a flag with the given name

func (*FlagSet) GetUint64Slice

func (f *FlagSet) GetUint64Slice(name string) ([]uint64, error)

GetUint64Slice return the []uint64 value of a flag with the given name

func (*FlagSet) GetUint8

func (f *FlagSet) GetUint8(name string) (uint8, error)

GetUint8 return the uint8 value of a flag with the given name

func (*FlagSet) GetUint8Slice

func (f *FlagSet) GetUint8Slice(name string) ([]uint8, error)

GetUint8Slice return the []uint8 value of a flag with the given name

func (*FlagSet) GetUintSlice

func (f *FlagSet) GetUintSlice(name string) ([]uint, error)

GetUintSlice returns the []uint value of a flag with the given name.

func (*FlagSet) GetUnknownFlags

func (f *FlagSet) GetUnknownFlags() []string

GetUnknownFlags returns unknown flags in the order they were Parsed. This requires ParseErrorsWhitelist.UnknownFlags to be set so that parsing does not abort on the first unknown flag.

func (*FlagSet) Groups

func (f *FlagSet) Groups() []string

Groups return an array of unique flag groups sorted in the same order as flags. Empty group (unassigned) is always placed at the beginning.

func (*FlagSet) HasAvailableFlags

func (f *FlagSet) HasAvailableFlags() bool

HasAvailableFlags returns a bool to indicate if the FlagSet has any flags that are not hidden.

func (*FlagSet) HasFlags

func (f *FlagSet) HasFlags() bool

HasFlags returns a bool to indicate if the FlagSet has any flags defined.

func (*FlagSet) IP

func (f *FlagSet) IP(name string, value net.IP, usage string, opts ...Opt) *net.IP

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

func (*FlagSet) IPMask

func (f *FlagSet) IPMask(name string, value net.IPMask, usage string, opts ...Opt) *net.IPMask

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

func (*FlagSet) IPMaskVar

func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string, opts ...Opt)

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

func (*FlagSet) IPNet

func (f *FlagSet) IPNet(name string, value net.IPNet, usage string, opts ...Opt) *net.IPNet

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

func (*FlagSet) IPNetSlice

func (f *FlagSet) IPNetSlice(name string, value []net.IPNet, usage string, opts ...Opt) *[]net.IPNet

IPNetSlice defines a []net.IPNet flag with specified name, default value, and usage string. The return value is the address of a []net.IPNet variable that stores the value of the flag.

func (*FlagSet) IPNetSliceVar

func (f *FlagSet) IPNetSliceVar(p *[]net.IPNet, name string, value []net.IPNet, usage string, opts ...Opt)

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

func (*FlagSet) IPNetVar

func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string, opts ...Opt)

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

func (*FlagSet) IPSlice

func (f *FlagSet) IPSlice(name string, value []net.IP, usage string, opts ...Opt) *[]net.IP

IPSlice defines a []net.IP flag with specified name, default value, and usage string. The return value is the address of a []net.IP variable that stores the value of the flag.

func (*FlagSet) IPSliceVar

func (f *FlagSet) IPSliceVar(p *[]net.IP, name string, value []net.IP, usage string, opts ...Opt)

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

func (*FlagSet) IPVar

func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string, opts ...Opt)

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

func (*FlagSet) Init

func (f *FlagSet) Init(name string, errorHandling ErrorHandling)

Init sets the name and error handling property for a flag set. By default, the zero FlagSet uses an empty name and the ContinueOnError error handling policy.

func (*FlagSet) Int

func (f *FlagSet) Int(name string, value int, usage string, opts ...Opt) *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 (*FlagSet) Int16

func (f *FlagSet) Int16(name string, value int16, usage string, opts ...Opt) *int16

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

func (*FlagSet) Int16Slice

func (f *FlagSet) Int16Slice(name string, value []int16, usage string, opts ...Opt) *[]int16

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

func (*FlagSet) Int16SliceVar

func (f *FlagSet) Int16SliceVar(p *[]int16, name string, value []int16, usage string, opts ...Opt)

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

func (*FlagSet) Int16Var

func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string, opts ...Opt)

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

func (*FlagSet) Int32

func (f *FlagSet) Int32(name string, value int32, usage string, opts ...Opt) *int32

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

func (*FlagSet) Int32Slice

func (f *FlagSet) Int32Slice(name string, value []int32, usage string, opts ...Opt) *[]int32

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

func (*FlagSet) Int32SliceVar

func (f *FlagSet) Int32SliceVar(p *[]int32, name string, value []int32, usage string, opts ...Opt)

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

func (*FlagSet) Int32Var

func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string, opts ...Opt)

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

func (*FlagSet) Int64

func (f *FlagSet) Int64(name string, value int64, usage string, opts ...Opt) *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 (*FlagSet) Int64Slice

func (f *FlagSet) Int64Slice(name string, value []int64, usage string, opts ...Opt) *[]int64

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

func (*FlagSet) Int64SliceVar

func (f *FlagSet) Int64SliceVar(p *[]int64, name string, value []int64, usage string, opts ...Opt)

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

func (*FlagSet) Int64Var

func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string, opts ...Opt)

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 (*FlagSet) Int8

func (f *FlagSet) Int8(name string, value int8, usage string, opts ...Opt) *int8

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

func (*FlagSet) Int8Slice

func (f *FlagSet) Int8Slice(name string, value []int8, usage string, opts ...Opt) *[]int8

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

func (*FlagSet) Int8SliceVar

func (f *FlagSet) Int8SliceVar(p *[]int8, name string, value []int8, usage string, opts ...Opt)

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

func (*FlagSet) Int8Var

func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string, opts ...Opt)

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

func (*FlagSet) IntSlice

func (f *FlagSet) IntSlice(name string, value []int, usage string, opts ...Opt) *[]int

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

func (*FlagSet) IntSliceVar

func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string, opts ...Opt)

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

func (*FlagSet) IntVar

func (f *FlagSet) IntVar(p *int, name string, value int, usage string, opts ...Opt)

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 (*FlagSet) Lookup

func (f *FlagSet) Lookup(name string) *Flag

Lookup returns the Flag structure of the named flag, returning nil if none exists.

func (*FlagSet) MustGetBool

func (f *FlagSet) MustGetBool(name string) bool

MustGetBool is like GetBool, but panics on error.

func (*FlagSet) MustGetBoolSlice

func (f *FlagSet) MustGetBoolSlice(name string) []bool

MustGetBoolSlice is like GetBoolSlice, but panics on error.

func (*FlagSet) MustGetBytesBase64

func (f *FlagSet) MustGetBytesBase64(name string) []byte

MustGetBytesBase64 is like GetBytesBase64, but panics on error.

func (*FlagSet) MustGetBytesHex

func (f *FlagSet) MustGetBytesHex(name string) []byte

MustGetBytesHex is like GetBytesHex, but panics on error.

func (*FlagSet) MustGetComplex128

func (f *FlagSet) MustGetComplex128(name string) complex128

MustGetComplex128 is like GetComplex128, but panics on error.

func (*FlagSet) MustGetComplex128Slice

func (f *FlagSet) MustGetComplex128Slice(name string) []complex128

MustGetComplex128Slice is like GetComplex128Slice, but panics on error.

func (*FlagSet) MustGetCount

func (f *FlagSet) MustGetCount(name string) int

MustGetCount is like GetCount, but panics on error.

func (*FlagSet) MustGetDuration

func (f *FlagSet) MustGetDuration(name string) time.Duration

MustGetDuration is like GetDuration, but panics on error.

func (*FlagSet) MustGetDurationSlice

func (f *FlagSet) MustGetDurationSlice(name string) []time.Duration

MustGetDurationSlice is like GetDurationSlice, but panics on error.

func (*FlagSet) MustGetFloat32

func (f *FlagSet) MustGetFloat32(name string) float32

MustGetFloat32 is like GetFloat32, but panics on error.

func (*FlagSet) MustGetFloat32Slice

func (f *FlagSet) MustGetFloat32Slice(name string) []float32

MustGetFloat32Slice is like GetFloat32Slice, but panics on error.

func (*FlagSet) MustGetFloat64

func (f *FlagSet) MustGetFloat64(name string) float64

MustGetFloat64 is like GetFloat64, but panics on error.

func (*FlagSet) MustGetFloat64Slice

func (f *FlagSet) MustGetFloat64Slice(name string) []float64

MustGetFloat64Slice is like GetFloat64Slice, but panics on error.

func (*FlagSet) MustGetIP

func (f *FlagSet) MustGetIP(name string) net.IP

MustGetIP is like GetIP, but panics on error.

func (*FlagSet) MustGetIPNet

func (f *FlagSet) MustGetIPNet(name string) net.IPNet

MustGetIPNet is like GetIPNet, but panics on error.

func (*FlagSet) MustGetIPNetSlice

func (f *FlagSet) MustGetIPNetSlice(name string) []net.IPNet

MustGetIPNetSlice is like GetIPNetSlice, but panics on error.

func (*FlagSet) MustGetIPSlice

func (f *FlagSet) MustGetIPSlice(name string) []net.IP

MustGetIPSlice is like GetIPSlice, but panics on error.

func (*FlagSet) MustGetIPv4Mask

func (f *FlagSet) MustGetIPv4Mask(name string) net.IPMask

MustGetIPv4Mask is like GetIPv4Mask, but panics on error.

func (*FlagSet) MustGetInt

func (f *FlagSet) MustGetInt(name string) int

MustGetInt is like GetInt, but panics on error.

func (*FlagSet) MustGetInt16

func (f *FlagSet) MustGetInt16(name string) int16

MustGetInt16 is like GetInt16, but panics on error.

func (*FlagSet) MustGetInt16Slice

func (f *FlagSet) MustGetInt16Slice(name string) []int16

MustGetInt16Slice is like GetInt16Slice, but panics on error.

func (*FlagSet) MustGetInt32

func (f *FlagSet) MustGetInt32(name string) int32

MustGetInt32 is like GetInt32, but panics on error.

func (*FlagSet) MustGetInt32Slice

func (f *FlagSet) MustGetInt32Slice(name string) []int32

MustGetInt32Slice is like GetInt32Slice, but panics on error.

func (*FlagSet) MustGetInt64

func (f *FlagSet) MustGetInt64(name string) int64

MustGetInt64 is like GetInt64, but panics on error.

func (*FlagSet) MustGetInt64Slice

func (f *FlagSet) MustGetInt64Slice(name string) []int64

MustGetInt64Slice is like GetInt64Slice, but panics on error.

func (*FlagSet) MustGetInt8

func (f *FlagSet) MustGetInt8(name string) int8

MustGetInt8 is like GetInt8, but panics on error.

func (*FlagSet) MustGetInt8Slice

func (f *FlagSet) MustGetInt8Slice(name string) []int8

MustGetInt8Slice is like GetInt8Slice, but panics on error.

func (*FlagSet) MustGetIntSlice

func (f *FlagSet) MustGetIntSlice(name string) []int

MustGetIntSlice is like GetIntSlice, but panics on error.

func (*FlagSet) MustGetString

func (f *FlagSet) MustGetString(name string) string

MustGetString is like GetString, but panics on error.

func (*FlagSet) MustGetStringArray

func (f *FlagSet) MustGetStringArray(name string) []string

MustGetStringArray is like GetStringArray, but panics on error.

func (*FlagSet) MustGetStringSlice

func (f *FlagSet) MustGetStringSlice(name string) []string

MustGetStringSlice is like GetStringSlice, but panics on error.

func (*FlagSet) MustGetStringToInt

func (f *FlagSet) MustGetStringToInt(name string) map[string]int

MustGetStringToInt is like GetStringToInt, but panics on error.

func (*FlagSet) MustGetStringToInt64

func (f *FlagSet) MustGetStringToInt64(name string) map[string]int64

MustGetStringToInt64 is like GetStringToInt64, but panics on error.

func (*FlagSet) MustGetStringToString

func (f *FlagSet) MustGetStringToString(name string) map[string]string

MustGetStringToString is like GetStringToString, but panics on error.

func (*FlagSet) MustGetUint

func (f *FlagSet) MustGetUint(name string) uint

MustGetUint is like GetUint, but panics on error.

func (*FlagSet) MustGetUint16

func (f *FlagSet) MustGetUint16(name string) uint16

MustGetUint16 is like GetUint16, but panics on error.

func (*FlagSet) MustGetUint16Slice

func (f *FlagSet) MustGetUint16Slice(name string) []uint16

MustGetUint16Slice is like GetUint16Slice, but panics on error.

func (*FlagSet) MustGetUint32

func (f *FlagSet) MustGetUint32(name string) uint32

MustGetUint32 is like GetUint32, but panics on error.

func (*FlagSet) MustGetUint32Slice

func (f *FlagSet) MustGetUint32Slice(name string) []uint32

MustGetUint32Slice is like GetUint32Slice, but panics on error.

func (*FlagSet) MustGetUint64

func (f *FlagSet) MustGetUint64(name string) uint64

MustGetUint64 is like GetUint64, but panics on error.

func (*FlagSet) MustGetUint64Slice

func (f *FlagSet) MustGetUint64Slice(name string) []uint64

MustGetUint64Slice is like GetUint64Slice, but panics on error.

func (*FlagSet) MustGetUint8

func (f *FlagSet) MustGetUint8(name string) uint8

MustGetUint8 is like GetUint8, but panics on error.

func (*FlagSet) MustGetUint8Slice

func (f *FlagSet) MustGetUint8Slice(name string) []uint8

MustGetUint8Slice is like GetUint8Slice, but panics on error.

func (*FlagSet) MustGetUintSlice

func (f *FlagSet) MustGetUintSlice(name string) []uint

MustGetUintSlice is like GetUintSlice, but panics on error.

func (*FlagSet) NArg

func (f *FlagSet) NArg() int

NArg is the number of arguments remaining after flags have been processed.

func (*FlagSet) NFlag

func (f *FlagSet) NFlag() int

NFlag returns the number of flags that have been set.

func (*FlagSet) Name

func (f *FlagSet) Name() string

Name returns the name of the flag set.

func (*FlagSet) Output

func (f *FlagSet) Output() io.Writer

Output returns the destination for usage and error messages. os.Stderr is returned if output was not set or was set to nil.

func (*FlagSet) Parse

func (f *FlagSet) Parse(arguments []string) error

Parse parses flag definitions from the argument list, which should not include the command name. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program. The return value will be ErrHelp if -help was set but not defined.

func (*FlagSet) ParseAll

func (f *FlagSet) ParseAll(arguments []string, fn func(flag *Flag, value string) error) error

ParseAll parses flag definitions from the argument list, which should not include the command name. The arguments for fn are flag and value. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program. The return value will be ErrHelp if -help was set but not defined.

func (*FlagSet) Parsed

func (f *FlagSet) Parsed() bool

Parsed reports whether f.Parse has been called.

func (*FlagSet) PrintDefaults

func (f *FlagSet) PrintDefaults()

PrintDefaults prints to standard error unless configured otherwise, the default values of all defined command-line flags in the set. See the documentation for the global function PrintDefaults for more information.

func (*FlagSet) Set

func (f *FlagSet) Set(name, value string) error

Set sets the value of the named flag.

func (*FlagSet) SetAnnotation

func (f *FlagSet) SetAnnotation(name, key string, values []string) error

SetAnnotation allows one to set arbitrary annotations on a flag in the FlagSet. This is sometimes used by gowarden/zulu programs which want to generate additional bash completion information.

func (*FlagSet) SetInterspersed

func (f *FlagSet) SetInterspersed(interspersed bool)

SetInterspersed sets whether to support interspersed option/non-option arguments.

func (*FlagSet) SetNormalizeFunc

func (f *FlagSet) SetNormalizeFunc(n func(f *FlagSet, name string) NormalizedName)

SetNormalizeFunc allows you to add a function which can translate flag names. Flags added to the FlagSet will be translated and then when anything tries to look up the flag that will also be translated. So it would be possible to create a flag named "getURL" and have it translated to "geturl". A user could then pass "--getUrl" which may also be translated to "geturl" and everything will work.

func (*FlagSet) SetOutput

func (f *FlagSet) SetOutput(output io.Writer)

SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.

func (*FlagSet) ShorthandLookup

func (f *FlagSet) ShorthandLookup(name rune) *Flag

ShorthandLookup returns the Flag structure of the shorthand flag, returning nil if none exists.

Example
name := "verbose"
short := 'v'

fs := NewFlagSet("Example", ContinueOnError)
fs.Bool(name, false, "verbose output", OptShorthand(short))

// len(short) must be == 1
flag := fs.ShorthandLookup(short)

fmt.Println(flag.Name)
Output:

func (*FlagSet) ShorthandLookupStr

func (f *FlagSet) ShorthandLookupStr(name string) *Flag

ShorthandLookupStr is the same as ShorthandLookup, but you can look it up through a string. It panics if name contains more than one UTF-8 character.

func (*FlagSet) String

func (f *FlagSet) String(name string, value string, usage string, opts ...Opt) *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 (*FlagSet) StringArray

func (f *FlagSet) StringArray(name string, value []string, usage string, opts ...Opt) *[]string

StringArray 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. Compared to StringSlice flags, a StringArray will not be split on commas.

func (*FlagSet) StringArrayVar

func (f *FlagSet) StringArrayVar(p *[]string, name string, value []string, usage string, opts ...Opt)

StringArrayVar 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. Compared to StringSlice flags, a StringArray will not be split on commas.

func (*FlagSet) StringSlice

func (f *FlagSet) StringSlice(name string, value []string, usage string, opts ...Opt) *[]string

StringSlice 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. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:

--ss="v1,v2" --ss="v3"

will result in

[]string{"v1", "v2", "v3"}

func (*FlagSet) StringSliceVar

func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string, opts ...Opt)

StringSliceVar 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. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:

--ss="v1,v2" --ss="v3"

will result in

[]string{"v1", "v2", "v3"}

func (*FlagSet) StringToInt

func (f *FlagSet) StringToInt(name string, value map[string]int, usage string, opts ...Opt) *map[string]int

StringToInt defines a map[string]int flag with specified name, default value, and usage string. The return value is the address of a map[string]int variable that stores the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func (*FlagSet) StringToInt64

func (f *FlagSet) StringToInt64(name string, value map[string]int64, usage string, opts ...Opt) *map[string]int64

StringToInt64 defines a map[string]int64 flag with specified name, default value, and usage string. The return value is the address of a map[string]int64 variable that stores the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func (*FlagSet) StringToInt64Var

func (f *FlagSet) StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string, opts ...Opt)

StringToInt64Var defines a map[string]int64 flag with specified name, default value, and usage string. The argument p points to a map[string]int64 variable in which to store the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func (*FlagSet) StringToIntVar

func (f *FlagSet) StringToIntVar(p *map[string]int, name string, value map[string]int, usage string, opts ...Opt)

StringToIntVar defines a map[string]int flag with specified name, default value, and usage string. The argument p points to a map[string]int variable in which to store the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func (*FlagSet) StringToString

func (f *FlagSet) StringToString(name string, value map[string]string, usage string, opts ...Opt) *map[string]string

StringToString defines a map[string]string flag with specified name, default value, and usage string. The return value is the address of a map[string]string variable that stores the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func (*FlagSet) StringToStringVar

func (f *FlagSet) StringToStringVar(p *map[string]string, name string, value map[string]string, usage string, opts ...Opt)

StringToStringVar defines a map[string]string flag with specified name, default value, and usage string. The argument p points to a map[string]string variable in which to store the values of multiple flags. The values will be separated on comma. Items can be quoted, or escape commas to avoid splitting.

func (*FlagSet) StringVar

func (f *FlagSet) StringVar(p *string, name string, value string, usage string, opts ...Opt)

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 (*FlagSet) Uint

func (f *FlagSet) Uint(name string, value uint, usage string, opts ...Opt) *uint

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

func (*FlagSet) Uint16

func (f *FlagSet) Uint16(name string, value uint16, usage string, opts ...Opt) *uint16

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

func (*FlagSet) Uint16Slice

func (f *FlagSet) Uint16Slice(name string, value []uint16, usage string, opts ...Opt) *[]uint16

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

func (*FlagSet) Uint16SliceVar

func (f *FlagSet) Uint16SliceVar(p *[]uint16, name string, value []uint16, usage string, opts ...Opt)

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

func (*FlagSet) Uint16Var

func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string, opts ...Opt)

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

func (*FlagSet) Uint32

func (f *FlagSet) Uint32(name string, value uint32, usage string, opts ...Opt) *uint32

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

func (*FlagSet) Uint32Slice

func (f *FlagSet) Uint32Slice(name string, value []uint32, usage string, opts ...Opt) *[]uint32

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

func (*FlagSet) Uint32SliceVar

func (f *FlagSet) Uint32SliceVar(p *[]uint32, name string, value []uint32, usage string, opts ...Opt)

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

func (*FlagSet) Uint32Var

func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string, opts ...Opt)

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

func (*FlagSet) Uint64

func (f *FlagSet) Uint64(name string, value uint64, usage string, opts ...Opt) *uint64

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

func (*FlagSet) Uint64Slice

func (f *FlagSet) Uint64Slice(name string, value []uint64, usage string, opts ...Opt) *[]uint64

Uint64Slice 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 (*FlagSet) Uint64SliceVar

func (f *FlagSet) Uint64SliceVar(p *[]uint64, name string, value []uint64, usage string, opts ...Opt)

Uint64SliceVar 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 (*FlagSet) Uint64Var

func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string, opts ...Opt)

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

func (*FlagSet) Uint8

func (f *FlagSet) Uint8(name string, value uint8, usage string, opts ...Opt) *uint8

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

func (*FlagSet) Uint8Slice

func (f *FlagSet) Uint8Slice(name string, value []uint8, usage string, opts ...Opt) *[]uint8

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

func (*FlagSet) Uint8SliceVar

func (f *FlagSet) Uint8SliceVar(p *[]uint8, name string, value []uint8, usage string, opts ...Opt)

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

func (*FlagSet) Uint8Var

func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string, opts ...Opt)

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

func (*FlagSet) UintSlice

func (f *FlagSet) UintSlice(name string, value []uint, usage string, opts ...Opt) *[]uint

UintSlice 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 (*FlagSet) UintSliceVar

func (f *FlagSet) UintSliceVar(p *[]uint, name string, value []uint, usage string, opts ...Opt)

UintSliceVar 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.

func (*FlagSet) UintVar

func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string, opts ...Opt)

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

func (*FlagSet) Var

func (f *FlagSet) Var(value Value, name, usage string, opts ...Opt) *Flag

Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.

func (*FlagSet) Visit

func (f *FlagSet) Visit(fn func(*Flag))

Visit visits the flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits only those flags that have been set.

func (*FlagSet) VisitAll

func (f *FlagSet) VisitAll(fn func(*Flag))

VisitAll visits the flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits all flags, even those not set.

type FlagUsageFormatter

type FlagUsageFormatter interface {
	Name(*Flag) string
	Usage(*Flag, string) string
	UsageVarName(*Flag, string) string
	DefaultValue(*Flag) string
	NoOptDefValue(*Flag) string
	Deprecated(*Flag) string
}

type Getter

type Getter interface {
	Value
	Get() interface{}
}

type NormalizedName

type NormalizedName string

NormalizedName is a flag name that has been normalized according to rules for the FlagSet (e.g. making '-' and '_' equivalent).

type Opt

type Opt interface {
	// contains filtered or unexported methods
}

func OptAnnotation

func OptAnnotation(key string, value []string) Opt

OptAnnotation Use it to annotate this specific flag for your application

func OptDefValue

func OptDefValue(defValue string) Opt

OptDefValue default value (as text); for usage message

func OptDeprecated

func OptDeprecated(msg string) Opt

OptDeprecated indicated that a flag is deprecated in your program. It will continue to function but will not show up in help or usage messages. Using this flag will also print the given usageMessage.

func OptDisablePrintDefault

func OptDisablePrintDefault(o bool) Opt

OptDisablePrintDefault toggle printing of the default value in usage message

func OptDisableUnquoteUsage

func OptDisableUnquoteUsage() Opt

OptDisableUnquoteUsage disable unquoting and extraction of type from usage

func OptGroup

func OptGroup(group string) Opt

OptGroup flag group

func OptHidden

func OptHidden() Opt

OptHidden used by zulu.Command to allow flags to be hidden from help/usage text

func OptNoOptDefVal

func OptNoOptDefVal(noOptDefVal string) Opt

OptNoOptDefVal default value (as text); if the flag is on the command line without any options

func OptShorthand

func OptShorthand(o rune) Opt

OptShorthand one-letter abbreviated flag

func OptShorthandDeprecated

func OptShorthandDeprecated(msg string) Opt

OptShorthandDeprecated If the shorthand of this flag is deprecated, this string is the new or now thing to use

func OptShorthandOnly

func OptShorthandOnly() Opt

OptShorthandOnly If the user set only the shorthand

func OptShorthandStr

func OptShorthandStr(shorthand string) Opt

OptShorthandStr one-letter abbreviated flag

func OptUsageType

func OptUsageType(usageType string) Opt

OptUsageType flag type displayed in the help message

type ParseErrorsAllowlist

type ParseErrorsAllowlist struct {
	// UnknownFlags will ignore unknown flags errors and continue parsing rest of the flags
	// See GetUnknownFlags to retrieve collected unknowns.
	UnknownFlags bool
}

ParseErrorsAllowlist defines the parsing errors that can be ignored

type SliceValue

type SliceValue interface {
	// Append adds the specified value to the end of the flag value list.
	Append(string) error
	// Replace will fully overwrite any data currently in the flag value list.
	Replace([]string) error
	// GetSlice returns the flag value list as an array of strings.
	GetSlice() []string
}

SliceValue is a secondary interface to all flags which hold a list of values. This allows full control over the value of list flags, and avoids complicated marshalling and unmarshalling to csv.

type Typed

type Typed interface {
	Type() string
}

Typed is an interface of Values that can communicate their type.

type Value

type Value interface {
	String() string
	Set(string) error
}

Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.)

Jump to

Keyboard shortcuts

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