golf

package module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: BSD-3-Clause Imports: 9 Imported by: 51

README

golf

Go long flag: a light-weight long and short command line option parser.

Description

golf is a modest options parsing library for Go command line interface programs. Meant to be small, like flag included in Go's standard library, golf does not re-architect how you make command line programs, nor request you use a DSL for describing your command line program. It merely allows you to specify which options your program accepts, and provides the values to your program based on the user's arguments.

  • Fully POSIX-compliant flags, including short & long flags.
  • Helpful functions for printing help and usage information.
  • Optional space between short flag and its argument.
  • No new concepts to learn beyond typical use of flag library.
  • Supports GNU extension allowing flags to appear intermixed with other command line arguments.

Usage

Documentation is available via GoDoc.

Drop-In Example

When the flag package prefix is changed to golf, your program will require a single-hyphen when the flag name is one rune long, and a double-hyphen prefix when the flag is more than one rune long.

$ example -v --limit 3

Drop-in compatibiliy usage is nearly identical to the standard library flag package, with a few additions for supporting flags with both short and long style options, albeit with a few features from the standard library not supported. However, it provides all the functions that most command line programs would require.

golf is designed such that you can change every flag package prefix to golf, recompile your program, and be able to use more POSIX friendly command line options. Both Type and TypeVar style flag declarations are supported, as shown below:

package main

import (
    "fmt"

    "github.com/karrick/golf"
)

func main() {
    // 'Type' functions are exactly like their corresponding functions from
    // the 'flag' standard library. However the length of the argument string
    // determines whether a single or double-hyphen prefix is used to change
    // its value. When this argument is a single rune long string then a
    // single-hyphen prefix is used to change its value, for example, "V" will
    // configure the parser to associate '-V' with the option. Otherwise a
    // double-hyphen prefix is used to change its value, for example,
    // "version" will configure the parser to associate '--version' with the
    // option.
    optType1 := golf.Bool("b", false, "can take a one rune flag name and return a variable pointer")
    otpType2 := golf.String("id", "", "can also take a multiple rune flag name and return a variable pointer")

    // 'TypeP' functions take two arguments. The first argument is a rune to
    // be associated with a single-hyphen prefix, for example, '-V'. The
    // second argument is a string to be associated with a double-hyphen
    // prefix, for example, '--version'.
    optTypeP := golf.DurationP('d', "duration", 0, "takes a one rune and a multiple rune flag name and returns a pointer to a variable")

    // The difference between 'Type' and 'TypeVar' is 'Type' returns a pointer
    // to a variable, whereas 'TypeVar' accepts a pointer to a variable.
    var optTypeVar float64
    golf.FloatVar(&optTypeVar, "f", 6.02e-23, "optTypeVar takes a pointer to a variable and a single flag")

    // For completeness, a 'TypeVarP' set of functions is also provided.
    var optTypeVarP int64
    golf.Int64VarP(&optTypeVarP, 'i', "int64", 13, "optTypeVarP takes a pointer to a variable, a rune, and a string")

    // After the options have been declared, the `golf.Parse()` function will
    // parse the command line options from `os.Args`.
    golf.Parse()

    // Notice that the returned 'Type' and 'TypeP' functions return a pointer
    // that must be referenced in order to obtain the value.
    fmt.Println("optType: ", *optType1)
    fmt.Println("optTypeP: ", *optTypeP)

    // In contrast, the 'TypeVar' and 'TypeVarP' functions accept a pointer to
    // the variable for the library to store its value, and accessing the
    // value does not require a pointer dereference.
    fmt.Println("optTypeVar: ", optTypeVar)
    fmt.Println("optTypeVarP: ", optTypeVarP)
}
Parser

golf also provides support for one or more non-global golf.Parser instances, so different golf.Parser instances can be created to parse different combinations of options, for instance, when different sub-commands support differing sets of options.

package main

import (
    "errors"
    "fmt"
    "os"
    "path/filepath"

    "github.com/karrick/golf"
)

func main() {
    // As a reminder, the first argument provided is the name of the
    // program. Therefore if there is only a single command line argument,
    // then the caller did not provide a sub-command.
    if len(os.Args) == 1 {
        bail(errors.New("missing sub-command"))
    }

    // os.Args[0]:  The string used to invoke the program.
    subCommand := os.Args[1]      // The sub-command.
    subCommandArgs := os.Args[2:] // Arguments to the sub-command.

    switch subCommand {
    case "foo":
        foo(subCommandArgs)
    case "bar":
        bar(subCommandArgs)
    default:
        bail(fmt.Errorf("sub-command not recognized: %q", subCommand))
    }
}

func foo(args []string) {
    // Declare and configure a parser to handle the command line options for
    // the 'foo' sub-command.
    var p golf.Parser
    optBool := p.WithBool("b", false, "some bool")
    optDuration := p.WithDurationP('d', "duration", 0, "some duration")

    // After the parser has been configured, use it to parse the command line
    // arguments provided to this function.
    err := p.Parse(args)
    if err != nil {
        bail(err)
    }

    // Do the sub-command operation with the arguments.
    fmt.Println("optBool:", *optBool)
    fmt.Println("optDuration:", *optDuration)

    // The 'Args' method returns a slice of strings that were not consumed by
    // the Parser variables.
    for i, arg := range p.Args() {
        fmt.Fprintf(os.Stderr, "# %d: %s\n", i, arg)
    }
}

func bar(args []string) {
    // Declare and configure a parser to handle the command line options for
    // the 'bar' sub-command.
    var p golf.Parser
    optInt := p.WithInt("i", 0, "some int")
    optString := p.WithString("s", "", "some string")

    // After the parser has been configured, use it to parse the command line
    // arguments provided to this function.
    err := p.Parse(args)
    if err != nil {
        bail(err)
    }

    // Do the sub-command operation with the arguments.
    fmt.Println("optInt:", *optInt)
    fmt.Println("optString:", *optString)

    // The 'Args' method returns a slice of strings that were not consumed by
    // the Parser variables.
    for i, arg := range p.Args() {
        fmt.Fprintf(os.Stderr, "# %d: %s\n", i, arg)
    }
}

func bail(err error) {
    basename := filepath.Base(os.Args[0])
    fmt.Fprintf(os.Stderr, "%s: %s\n", basename, err)
    fmt.Fprintf(os.Stderr, "USAGE %s foo [-b] [-d DURATION]\n", basename)
    fmt.Fprintf(os.Stderr, "USAGE %s bar [-i INT] [-s STRING]\n", basename)
    os.Exit(2)
}

Features

golf allows specifying both a short and a long flag name by calling the same function stem but with a P suffix, as shown below. When declaring a short and long flag pair, the short flag type is a rune, to prevent accidentally initializing a command line flag pair with two multi-rune strings, which is not allowed. (The reason for this compromise is because the command line flag declaration pattern used by flag provides no means for signalling an error.)

optRaw := golf.BoolP('r', "raw", false, "Display raw output")
optServer := golf.StringP('s', "server", "", "Send query to specified server")
optTheshold := golf.FloatP('t', "threshold", 0, "Set minimum threshold")
optVerbose := golf.BoolP('v', "verbose", false, "Display verbose output")
golf.Parse()

All of the below examples result in the same flag values being set:

$ example -sfoo.example.com -t3.14
$ example -s foo.example.com -t 3.14
$ example --server foo.example.com --threshold 3.14

golf allows boolean options to be grouped together when using their single letter equivalents, such as common in many UNIX programs. all of the following are equivalent:

$ example -rv -t 4 -shost.example.com
$ example -rv -t4 -s host.example.com
$ example -rv --threshold 4 --server host.example.com
$ example -v -r --threshold 4 --server host.example.com

golf also allow concatenation of one or more boolean short flags with at most one short flag that requires an argument provided the flag that requires the argument is the last flag in the parameter. Both of the following are legal, although the second example happens to parse oddly in my brain, because v and t appear grouped closer than the t and the 4. Nevertheless, both are equivalent and unambiguous:

$ example -vt4
$ example -vt 4

To prevent ambiguities, however, golf does not allow placing any additional flags after a flag that requires an argument, even if it may appear to be legal, in the same argument. For instance, if the i takes an integer and the s flag takes a string, this will still result in a parsing error:

$ example -i4sfoo.example.com
ERROR: strconv.ParseInt: parsing "4sfoo.example.com": invalid syntax

This however is legal:

$ example -i4 -sfoo.example.com

In an attempt to be largely compatible with the flag library, specifying an option flag has no error return value, so attempting to create a flag with illegal arguments will panic. While causing a panic is poor practice for a library, if command line options are not correctly defined by the program the case will be caught early by running the program.

This library supports a common practice in GNU command line argument parsing that allows command line flags and command line arguments to be intermixed. For instance, the following invocations would be equivalent.

$ example -t 3.14 arg1 arg2
$ example arg1 -t3.14 arg2
$ example arg1 arg2 -t 3.14

Help Example

Invoking golf.Usage() will display the program name, followed by a list of command line option flags. The short and long flag names are displayed if they are both defined, otherwise, just the short or the long is displayed. After the flag name will be a token representing the expected value data type, so the user knows what type of parsing will be invoked on any value provided for that flag.

On a separate line after each flag is printed a tab character, followed by the description and the default value for that flag.

example version 1.2.3
    example program

Usage of example:
  -h, --help
    Display command line help and exit (default: false)
  -l, --limit int
    Limit output to specified number of lines (default: 0)
  -q, --quiet
    Do not print intermediate errors to stderr (default: false)
  -v, --verbose
    Print verbose output to stderr (default: false)
  -V, --version
    Print version to stderr and exit (default: false)
  -s, --servers string
    Some string (default: host1,host2)
  -t string
    Another string (default: host3,host4)
  --flubbers string
    Yet another string (default: host5)

TODO

  • Support remaining functions from flag package in the standard library.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Usage = func() {

	fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
	defaultParser.PrintDefaults()
}

Usage prints command line usage to stderr, but may be overridden by programs that need to customize the usage information.

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. Arg returns an empty string if the requested element does not exist.

func Args

func Args() []string

Args returns the non-flag command-line arguments.

func Bool

func Bool(flag string, value bool, description string) *bool

Bool returns a pointer to a bool command line option, allowing for either a short or a long flag. If both are desired, use the BoolP function.

func BoolP added in v0.1.0

func BoolP(short rune, long string, value bool, description string) *bool

BoolP returns a pointer to a bool command line option, allowing for both a short and a long flag.

func BoolVar added in v0.0.4

func BoolVar(pv *bool, flag string, value bool, description string)

BoolVar binds an existing boolean variable to a flag, allowing for either a short or a long flag. If both are desired, use the BoolVarP function.

func BoolVarP added in v0.1.0

func BoolVarP(pv *bool, short rune, long string, value bool, description string)

BoolVarP binds an existing boolean variable to a flag, allowing for both a short and a long flag.

func Duration

func Duration(flag string, value time.Duration, description string) *time.Duration

Duration returns a pointer to a time.Duration command line option, allowing for either a short or a long flag. If both are desired, use the DurationP function.

func DurationP added in v0.1.0

func DurationP(short rune, long string, value time.Duration, description string) *time.Duration

DurationP returns a pointer to a time.Duration command line option, allowing for both a short and a long flag.

func DurationVar added in v0.0.4

func DurationVar(pv *time.Duration, flag string, value time.Duration, description string)

DurationVar binds an existing time.Duration variable to a flag, allowing for either a short or a long flag. If both are desired, use the DurationVarP function.

func DurationVarP added in v0.1.0

func DurationVarP(pv *time.Duration, short rune, long string, value time.Duration, description string)

DurationVarP binds an existing time.Duration variable to a flag, allowing for both a short and a long flag.

func Float

func Float(flag string, value float64, description string) *float64

Float returns a pointer to a float64 command line option, allowing for either a short or a long flag. If both are desired, use the FloatP function.

func FloatP added in v0.1.0

func FloatP(short rune, long string, value float64, description string) *float64

FloatP returns a pointer to a float64 command line option, allowing for both a short and a long flag.

func FloatVar added in v0.0.4

func FloatVar(pv *float64, flag string, value float64, description string)

FloatVar binds an existing float64 variable to a flag, allowing for either a short or a long flag. If both are desired, use the FloatVarP function.

func FloatVarP added in v0.1.0

func FloatVarP(pv *float64, short rune, long string, value float64, description string)

FloatVarP binds an existing float64 variable to a flag, allowing for both a short and a long flag.

func Int

func Int(flag string, value int, description string) *int

Int returns a pointer to a int command line option, allowing for either a short or a long flag. If both are desired, use the IntP function.

func Int64

func Int64(flag string, value int64, description string) *int64

Int64 returns a pointer to a int64 command line option, allowing for either a short or a long flag. If both are desired, use the Int64P function.

func Int64P added in v0.1.0

func Int64P(short rune, long string, value int64, description string) *int64

Int64P returns a pointer to a int64 command line option, allowing for both a short and a long flag.

func Int64Var added in v0.0.4

func Int64Var(pv *int64, flag string, value int64, description string)

Int64Var binds an existing int64 variable to a flag, allowing for either a short or a long flag. If both are desired, use the Int64VarP function.

func Int64VarP added in v0.1.0

func Int64VarP(pv *int64, short rune, long string, value int64, description string)

Int64VarP binds an existing int64 variable to a flag, allowing for both a short and a long flag.

func IntP added in v0.1.0

func IntP(short rune, long string, value int, description string) *int

IntP returns a pointer to a int command line option, allowing for both a short and a long flag.

func IntVar added in v0.0.4

func IntVar(pv *int, flag string, value int, description string)

IntVar binds an existing int variable to a flag, allowing for either a short or a long flag. If both are desired, use the IntVarP function.

func IntVarP added in v0.1.0

func IntVarP(pv *int, short rune, long string, value int, description string)

IntVarP binds an existing int variable to a flag, allowing for both a short and a long flag.

func NArg

func NArg() int

NArg returns 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 processed.

func Parse

func Parse()

Parse parses the command line. On error, displays the usage of the command line and exits the program with status code 2.

func Parsed

func Parsed() bool

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

Deprecated

func PrintDefaults

func PrintDefaults()

PrintDefaults prints to standard error, a usage message showing the default settings of all defined command-line flags.

func PrintDefaultsTo added in v1.4.0

func PrintDefaultsTo(w io.Writer)

PrintDefaultsTo prints to w, a usage message showing the default settings of all defined command-line flags.

func String

func String(flag string, value string, description string) *string

String returns a postringer to a string command line option, allowing for either a short or a long flag. If both are desired, use the StringP function.

func StringP added in v0.1.0

func StringP(short rune, long string, value string, description string) *string

StringP returns a postringer to a string command line option, allowing for both a short and a long flag.

func StringVar added in v0.0.4

func StringVar(pv *string, flag string, value string, description string)

StringVar binds an existing string variable to a flag, allowing for either a short or a long flag. If both are desired, use the StringVarP function.

func StringVarP added in v0.1.0

func StringVarP(pv *string, short rune, long string, value string, description string)

StringVarP binds an existing string variable to a flag, allowing for both a short and a long flag.

func Uint

func Uint(flag string, value uint, description string) *uint

Uint returns a pouinter to a uint command line option, allowing for either a short or a long flag. If both are desired, use the UintP function.

func Uint64

func Uint64(flag string, value uint64, description string) *uint64

Uint64 returns a pointer to a uint64 command line option, allowing for either a short or a long flag. If both are desired, use the Uint64P function.

func Uint64P added in v0.1.0

func Uint64P(short rune, long string, value uint64, description string) *uint64

Uint64P returns a pointer to a uint64 command line option, allowing for both a short and a long flag.

func Uint64Var added in v0.0.4

func Uint64Var(pv *uint64, flag string, value uint64, description string)

Uint64Var binds an existing uint64 variable to a flag, allowing for either a short or a long flag. If both are desired, use the Uint64VarP function.

func Uint64VarP added in v0.1.0

func Uint64VarP(pv *uint64, short rune, long string, value uint64, description string)

Uint64VarP binds an existing uint64 variable to a flag, allowing for both a short and a long flag.

func UintP added in v0.1.0

func UintP(short rune, long string, value uint, description string) *uint

UintP returns a pouinter to a uint command line option, allowing for both a short and a long flag.

func UintVar added in v0.0.4

func UintVar(pv *uint, flag string, value uint, description string)

UintVar binds an existing uint variable to a flag, allowing for either a short or a long flag. If both are desired, use the UintVarP function.

func UintVarP added in v0.1.0

func UintVarP(pv *uint, short rune, long string, value uint, description string)

UintVarP binds an existing uint variable to a flag, allowing for both a short and a long flag.

func Wrap added in v1.3.0

func Wrap(input string) string

Wrap returns input string with leading and trailing whitespace removed, with the exception of exactly one trailing newline character, and intraline whitespace normalized to single spaces, except in cases where a word would exceed a line length of 80 columns, in which case a newline will be used rather than a space.

Types

type LineWrapper added in v1.3.0

type LineWrapper struct {
	// Prefix is the optional string to be places at the start of every output
	// line.
	Prefix string

	// Max is the optional maximum number of columns to wrap the text to. When
	// 0, the LineWrapper will wrap lines fit on in 80 columns.
	Max int
}

LineWrapper wraps input strings to specified maximum number of columns, or when zero, 80 columns. When Prefix is not empty string, it prefixes each line with the prefix string.

func (LineWrapper) Wrap added in v1.3.0

func (w LineWrapper) Wrap(input string) string

type Parser added in v1.5.0

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

Parser can parse a series of command line arguments.

func (*Parser) Arg added in v1.5.0

func (p *Parser) Arg(i int) string

Arg returns the i'th command-line argument. Arg(0) is the first remaining argument after flags have been processed. Arg returns an empty string if the requested element does not exist.

func (*Parser) Args added in v1.5.0

func (p *Parser) Args() []string

Args returns the non-flag command-line arguments.

func (*Parser) Err added in v1.5.0

func (p *Parser) Err() error

Err returns the error state of a parser.

func (*Parser) NArg added in v1.5.0

func (p *Parser) NArg() int

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

func (*Parser) NFlag added in v1.5.0

func (p *Parser) NFlag() int

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

func (*Parser) Parse added in v1.5.0

func (p *Parser) Parse(args []string) error

Parse parses args.

func (Parser) Parsed added in v1.5.0

func (p Parser) Parsed() bool

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

func (*Parser) PrintDefaults added in v1.5.0

func (p *Parser) PrintDefaults()

PrintDefaults prints to standard error, a usage message showing the default settings of all defined command-line flags.

func (*Parser) PrintDefaultsTo added in v1.5.0

func (p *Parser) PrintDefaultsTo(w io.Writer)

PrintDefaultsTo prints to w, a usage message showing the default settings of all defined command-line flags.

func (*Parser) WithBool added in v1.6.0

func (p *Parser) WithBool(flag string, value bool, description string) *bool

WithBool returns a pointer to a bool command line option, allowing for either a short or a long flag. If both are desired, use the BoolP function.

func (*Parser) WithBoolP added in v1.6.0

func (p *Parser) WithBoolP(short rune, long string, value bool, description string) *bool

WithBoolP returns a pointer to a bool command line option, allowing for both a short and a long flag.

func (*Parser) WithBoolVar added in v1.5.0

func (p *Parser) WithBoolVar(pv *bool, flag string, description string) *Parser

WithBoolVar updates the Parser to recognize flag as a bool with the default value and description.

func (*Parser) WithBoolVarP added in v1.5.0

func (p *Parser) WithBoolVarP(pv *bool, short rune, long string, description string) *Parser

WithBoolVar updates the Parser to recognize short and long flag as a bool with the default value and description.

func (*Parser) WithDuration added in v1.6.0

func (p *Parser) WithDuration(flag string, value time.Duration, description string) *time.Duration

WithDuration returns a pointer to a time.Duration command line option, allowing for either a short or a long flag. If both are desired, use the DurationP function.

func (*Parser) WithDurationP added in v1.6.0

func (p *Parser) WithDurationP(short rune, long string, value time.Duration, description string) *time.Duration

WithDurationP returns a pointer to a time.Duration command line option, allowing for both a short and a long flag.

func (*Parser) WithDurationVar added in v1.5.0

func (p *Parser) WithDurationVar(pv *time.Duration, flag string, description string) *Parser

WithDurationVar updates the Parser to recognize flag as a duration with the default value and description.

func (*Parser) WithDurationVarP added in v1.5.0

func (p *Parser) WithDurationVarP(pv *time.Duration, short rune, long string, description string) *Parser

WithDurationVar updates the Parser to recognize short and long flag as a duration with the default value and description.

func (*Parser) WithFloat added in v1.6.0

func (p *Parser) WithFloat(flag string, value float64, description string) *float64

WithFloat returns a pointer to a float64 command line option, allowing for either a short or a long flag. If both are desired, use the FloatP function.

func (*Parser) WithFloatP added in v1.6.0

func (p *Parser) WithFloatP(short rune, long string, value float64, description string) *float64

WithFloatP returns a pointer to a float64 command line option, allowing for both a short and a long flag.

func (*Parser) WithFloatVar added in v1.5.0

func (p *Parser) WithFloatVar(pv *float64, flag string, description string) *Parser

WithFloatVar updates the Parser to recognize flag as a float with the default value and description.

func (*Parser) WithFloatVarP added in v1.5.0

func (p *Parser) WithFloatVarP(pv *float64, short rune, long string, description string) *Parser

WithFloatVar updates the Parser to recognize short and long flag as a float with the default value and description.

func (*Parser) WithInt added in v1.6.0

func (p *Parser) WithInt(flag string, value int, description string) *int

WithInt returns a pointer to a int command line option, allowing for either a short or a long flag. If both are desired, use the IntP function.

func (*Parser) WithInt64 added in v1.6.0

func (p *Parser) WithInt64(flag string, value int64, description string) *int64

WithInt64 returns a pointer to a int64 command line option, allowing for either a short or a long flag. If both are desired, use the Int64P function.

func (*Parser) WithInt64P added in v1.6.0

func (p *Parser) WithInt64P(short rune, long string, value int64, description string) *int64

WithInt64P returns a pointer to a int64 command line option, allowing for both a short and a long flag.

func (*Parser) WithInt64Var added in v1.5.0

func (p *Parser) WithInt64Var(pv *int64, flag string, description string) *Parser

WithInt64Var updates the Parser to recognize flag as a int64 with the default value and description.

func (*Parser) WithInt64VarP added in v1.5.0

func (p *Parser) WithInt64VarP(pv *int64, short rune, long string, description string) *Parser

WithInt64Var updates the Parser to recognize short and long flag as a int64 with the default value and description.

func (*Parser) WithIntP added in v1.6.0

func (p *Parser) WithIntP(short rune, long string, value int, description string) *int

WithIntP returns a pointer to a int command line option, allowing for both a short and a long flag.

func (*Parser) WithIntVar added in v1.5.0

func (p *Parser) WithIntVar(pv *int, flag string, description string) *Parser

WithIntVar updates the Parser to recognize flag as a int with the default value and description.

func (*Parser) WithIntVarP added in v1.5.0

func (p *Parser) WithIntVarP(pv *int, short rune, long string, description string) *Parser

WithIntVar updates the Parser to recognize short and long flag as a int with the default value and description.

func (*Parser) WithString added in v1.6.0

func (p *Parser) WithString(flag string, value string, description string) *string

WithString returns a postringer to a string command line option, allowing for either a short or a long flag. If both are desired, use the StringP function.

func (*Parser) WithStringP added in v1.6.0

func (p *Parser) WithStringP(short rune, long string, value string, description string) *string

WithStringP returns a postringer to a string command line option, allowing for both a short and a long flag.

func (*Parser) WithStringVar added in v1.5.0

func (p *Parser) WithStringVar(pv *string, flag string, description string) *Parser

WithStringVar updates the Parser to recognize flag as a string with the default value and description.

func (*Parser) WithStringVarP added in v1.5.0

func (p *Parser) WithStringVarP(pv *string, short rune, long string, description string) *Parser

WithStringVar updates the Parser to recognize short and long flag as a string with the default value and description.

func (*Parser) WithUint added in v1.6.0

func (p *Parser) WithUint(flag string, value uint, description string) *uint

WithUint returns a pouinter to a uint command line option, allowing for either a short or a long flag. If both are desired, use the UintP function.

func (*Parser) WithUint64 added in v1.6.0

func (p *Parser) WithUint64(flag string, value uint64, description string) *uint64

WithUint64 returns a pouinter to a uint64 command line option, allowing for either a short or a long flag. If both are desired, use the Uint64P function.

func (*Parser) WithUint64P added in v1.6.0

func (p *Parser) WithUint64P(short rune, long string, value uint64, description string) *uint64

WithUint64P returns a pouinter to a uint64 command line option, allowing for both a short and a long flag.

func (*Parser) WithUint64Var added in v1.5.0

func (p *Parser) WithUint64Var(pv *uint64, flag string, description string) *Parser

WithUint64Var updates the Parser to recognize flag as a uint64 with the default value and description.

func (*Parser) WithUint64VarP added in v1.5.0

func (p *Parser) WithUint64VarP(pv *uint64, short rune, long string, description string) *Parser

WithUint64Var updates the Parser to recognize short and long flag as a uint64 with the default value and description.

func (*Parser) WithUintP added in v1.6.0

func (p *Parser) WithUintP(short rune, long string, value uint, description string) *uint

WithUintP returns a pouinter to a uint command line option, allowing for both a short and a long flag.

func (*Parser) WithUintVar added in v1.5.0

func (p *Parser) WithUintVar(pv *uint, flag string, description string) *Parser

WithUintVar updates the Parser to recognize flag as a uint with the default value and description.

func (*Parser) WithUintVarP added in v1.5.0

func (p *Parser) WithUintVarP(pv *uint, short rune, long string, description string) *Parser

WithUintVar updates the Parser to recognize short and long flag as a uint with the default value and description.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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