kingpin.v2: gopkg.in/alecthomas/kingpin.v2 Index | Examples | Files | Directories

package kingpin

import "gopkg.in/alecthomas/kingpin.v2"

Package kingpin provides command line interfaces like this:

$ chat
usage: chat [<flags>] <command> [<flags>] [<args> ...]

Flags:
  --debug              enable debug mode
  --help               Show help.
  --server=127.0.0.1   server address

Commands:
  help <command>
    Show help for a command.

  post [<flags>] <channel>
    Post a message to a channel.

  register <nick> <name>
    Register a new user.

$ chat help post
usage: chat [<flags>] post [<flags>] <channel> [<text>]

Post a message to a channel.

Flags:
  --image=IMAGE   image to post

Args:
  <channel>   channel to post to
  [<text>]    text to post
$ chat post --image=~/Downloads/owls.jpg pics

From code like this:

package main

import "gopkg.in/alecthomas/kingpin.v2"

var (
  debug    = kingpin.Flag("debug", "enable debug mode").Default("false").Bool()
  serverIP = kingpin.Flag("server", "server address").Default("127.0.0.1").IP()

  register     = kingpin.Command("register", "Register a new user.")
  registerNick = register.Arg("nick", "nickname for user").Required().String()
  registerName = register.Arg("name", "name of user").Required().String()

  post        = kingpin.Command("post", "Post a message to a channel.")
  postImage   = post.Flag("image", "image to post").ExistingFile()
  postChannel = post.Arg("channel", "channel to post to").Required().String()
  postText    = post.Arg("text", "text to post").String()
)

func main() {
  switch kingpin.Parse() {
  // Register user
  case "register":
    println(*registerNick)

  // Post message
  case "post":
    if *postImage != nil {
    }
    if *postText != "" {
    }
  }
}

Index

Examples

Package Files

actions.go app.go args.go cmd.go completions.go doc.go envar.go flags.go global.go guesswidth_unix.go model.go parser.go parsers.go templates.go usage.go values.go values_generated.go

Variables

var (
    // CommandLine is the default Kingpin parser.
    CommandLine = New(filepath.Base(os.Args[0]), "")
    // Global help flag. Exposed for user customisation.
    HelpFlag = CommandLine.HelpFlag
    // Top-level help command. Exposed for user customisation. May be nil.
    HelpCommand = CommandLine.HelpCommand
    // Global version flag. Exposed for user customisation. May be nil.
    VersionFlag = CommandLine.VersionFlag
)
var BashCompletionTemplate = "" /* 329 byte string literal not displayed */
var CompactUsageTemplate = "" /* 1256 byte string literal not displayed */

Usage template with compactly formatted commands.

var DefaultUsageTemplate = "" /* 1187 byte string literal not displayed */

Default usage template.

var (
    ErrCommandNotSpecified = fmt.Errorf("command not specified")
)
var LongHelpTemplate = "" /* 927 byte string literal not displayed */

Default usage template.

var ManPageTemplate = "" /* 1085 byte string literal not displayed */
var SeparateOptionalFlagsUsageTemplate = "" /* 1351 byte string literal not displayed */

Usage template where command's optional flags are listed separately

var (
    TokenEOLMarker = Token{-1, TokenEOL, ""}
)
var ZshCompletionTemplate = "" /* 426 byte string literal not displayed */

func Errorf Uses

func Errorf(format string, args ...interface{})

Errorf prints an error message to stderr.

func ExpandArgsFromFile Uses

func ExpandArgsFromFile(filename string) (out []string, err error)

Expand arguments from a file. Lines starting with # will be treated as comments.

func FatalIfError Uses

func FatalIfError(err error, format string, args ...interface{})

FatalIfError prints an error and exits if err is not nil. The error is printed with the given prefix.

func FatalUsage Uses

func FatalUsage(format string, args ...interface{})

FatalUsage prints an error message followed by usage information, then exits with a non-zero status.

func FatalUsageContext Uses

func FatalUsageContext(context *ParseContext, format string, args ...interface{})

FatalUsageContext writes a printf formatted error message to stderr, then usage information for the given ParseContext, before exiting.

func Fatalf Uses

func Fatalf(format string, args ...interface{})

Fatalf prints an error message to stderr and exits.

func MustParse Uses

func MustParse(command string, err error) string

MustParse can be used with app.Parse(args) to exit with an error if parsing fails.

func Parse Uses

func Parse() string

Parse and return the selected command. Will call the termination handler if an error is encountered.

func Usage Uses

func Usage()

Usage prints usage to stderr.

type Action Uses

type Action func(*ParseContext) error

Action callback executed at various stages after all values are populated. The application, commands, arguments and flags all have corresponding actions.

type Application Uses

type Application struct {
    Name string
    Help string

    // Help flag. Exposed for user customisation.
    HelpFlag *FlagClause
    // Help command. Exposed for user customisation. May be nil.
    HelpCommand *CmdClause
    // Version flag. Exposed for user customisation. May be nil.
    VersionFlag *FlagClause
    // contains filtered or unexported fields
}

An Application contains the definitions of flags, arguments and commands for an application.

func New Uses

func New(name, help string) *Application

New creates a new Kingpin application instance.

func UsageTemplate Uses

func UsageTemplate(template string) *Application

Set global usage template to use (defaults to DefaultUsageTemplate).

func Version Uses

func Version(version string) *Application

Version adds a flag for displaying the application version number.

func (*Application) Action Uses

func (a *Application) Action(action Action) *Application

Action callback to call when all values are populated and parsing is complete, but before any command, flag or argument actions.

All Action() callbacks are called in the order they are encountered on the command line.

func (*Application) Author Uses

func (a *Application) Author(author string) *Application

Author sets the author output by some help templates.

func (*Application) CmdCompletion Uses

func (c *Application) CmdCompletion(context *ParseContext) []string

CmdCompletion returns completion options for arguments, if that's where parsing left off, or commands if there aren't any unsatisfied args.

func (*Application) Command Uses

func (a *Application) Command(name, help string) *CmdClause

Command adds a new top-level command.

func (*Application) DefaultEnvars Uses

func (a *Application) DefaultEnvars() *Application

DefaultEnvars configures all flags (that do not already have an associated envar) to use a default environment variable in the form "<app>_<flag>".

For example, if the application is named "foo" and a flag is named "bar- waz" the environment variable: "FOO_BAR_WAZ".

func (*Application) ErrorWriter Uses

func (a *Application) ErrorWriter(w io.Writer) *Application

ErrorWriter sets the io.Writer to use for errors.

func (*Application) Errorf Uses

func (a *Application) Errorf(format string, args ...interface{})

Errorf prints an error message to w in the format "<appname>: error: <message>".

func (*Application) FatalIfError Uses

func (a *Application) FatalIfError(err error, format string, args ...interface{})

FatalIfError prints an error and exits if err is not nil. The error is printed with the given formatted string, if any.

func (*Application) FatalUsage Uses

func (a *Application) FatalUsage(format string, args ...interface{})

FatalUsage prints an error message followed by usage information, then exits with a non-zero status.

func (*Application) FatalUsageContext Uses

func (a *Application) FatalUsageContext(context *ParseContext, format string, args ...interface{})

FatalUsageContext writes a printf formatted error message to w, then usage information for the given ParseContext, before exiting.

func (*Application) Fatalf Uses

func (a *Application) Fatalf(format string, args ...interface{})

Fatalf writes a formatted error to w then terminates with exit status 1.

func (*Application) FlagCompletion Uses

func (c *Application) FlagCompletion(flagName string, flagValue string) (choices []string, flagMatch bool, optionMatch bool)

func (*Application) Interspersed Uses

func (a *Application) Interspersed(interspersed bool) *Application

Interspersed control if flags can be interspersed with positional arguments

true (the default) means that they can, false means that all the flags must appear before the first positional arguments.

func (*Application) Model Uses

func (a *Application) Model() *ApplicationModel

func (*Application) Parse Uses

func (a *Application) Parse(args []string) (command string, err error)

Parse parses command-line arguments. It returns the selected command and an error. The selected command will be a space separated subcommand, if subcommands have been configured.

This will populate all flag and argument values, call all callbacks, and so on.

func (*Application) ParseContext Uses

func (a *Application) ParseContext(args []string) (*ParseContext, error)

ParseContext parses the given command line and returns the fully populated ParseContext.

func (*Application) PreAction Uses

func (a *Application) PreAction(action Action) *Application

Action called after parsing completes but before validation and execution.

func (*Application) Terminate Uses

func (a *Application) Terminate(terminate func(int)) *Application

Terminate specifies the termination handler. Defaults to os.Exit(status). If nil is passed, a no-op function will be used.

func (*Application) Usage Uses

func (a *Application) Usage(args []string)

Usage writes application usage to w. It parses args to determine appropriate help context, such as which command to show help for.

func (*Application) UsageForContext Uses

func (a *Application) UsageForContext(context *ParseContext) error

UsageForContext displays usage information from a ParseContext (obtained from Application.ParseContext() or Action(f) callbacks).

func (*Application) UsageForContextWithTemplate Uses

func (a *Application) UsageForContextWithTemplate(context *ParseContext, indent int, tmpl string) error

UsageForContextWithTemplate is the base usage function. You generally don't need to use this.

func (*Application) UsageTemplate Uses

func (a *Application) UsageTemplate(template string) *Application

UsageTemplate specifies the text template to use when displaying usage information. The default is UsageTemplate.

func (*Application) UsageWriter Uses

func (a *Application) UsageWriter(w io.Writer) *Application

UsageWriter sets the io.Writer to use for errors.

func (*Application) Validate Uses

func (a *Application) Validate(validator ApplicationValidator) *Application

Validate sets a validation function to run when parsing.

func (*Application) Version Uses

func (a *Application) Version(version string) *Application

Version adds a --version flag for displaying the application version.

func (*Application) Writer Uses

func (a *Application) Writer(w io.Writer) *Application

Writer specifies the writer to use for usage and errors. Defaults to os.Stderr. DEPRECATED: See ErrorWriter and UsageWriter.

type ApplicationModel Uses

type ApplicationModel struct {
    Name    string
    Help    string
    Version string
    Author  string
    *ArgGroupModel
    *CmdGroupModel
    *FlagGroupModel
}

type ApplicationValidator Uses

type ApplicationValidator func(*Application) error

type ArgClause Uses

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

func Arg Uses

func Arg(name, help string) *ArgClause

Arg adds a new argument to the top-level of the default parser.

func (*ArgClause) Action Uses

func (a *ArgClause) Action(action Action) *ArgClause

func (*ArgClause) Bool Uses

func (p *ArgClause) Bool() (target *bool)

Bool parses the next command-line value as bool.

func (*ArgClause) BoolList Uses

func (p *ArgClause) BoolList() (target *[]bool)

BoolList accumulates bool values into a slice.

func (*ArgClause) BoolListVar Uses

func (p *ArgClause) BoolListVar(target *[]bool)

func (*ArgClause) BoolVar Uses

func (p *ArgClause) BoolVar(target *bool)

func (*ArgClause) Bytes Uses

func (p *ArgClause) Bytes() (target *units.Base2Bytes)

Bytes parses numeric byte units. eg. 1.5KB

func (*ArgClause) BytesVar Uses

func (p *ArgClause) BytesVar(target *units.Base2Bytes)

BytesVar parses numeric byte units. eg. 1.5KB

func (*ArgClause) Counter Uses

func (p *ArgClause) Counter() (target *int)

A Counter increments a number each time it is encountered.

func (*ArgClause) CounterVar Uses

func (p *ArgClause) CounterVar(target *int)

func (*ArgClause) Default Uses

func (a *ArgClause) Default(values ...string) *ArgClause

Default values for this argument. They *must* be parseable by the value of the argument.

func (*ArgClause) Duration Uses

func (p *ArgClause) Duration() (target *time.Duration)

Duration sets the parser to a time.Duration parser.

func (*ArgClause) DurationList Uses

func (p *ArgClause) DurationList() (target *[]time.Duration)

DurationList accumulates time.Duration values into a slice.

func (*ArgClause) DurationListVar Uses

func (p *ArgClause) DurationListVar(target *[]time.Duration)

func (*ArgClause) DurationVar Uses

func (p *ArgClause) DurationVar(target *time.Duration)

Duration sets the parser to a time.Duration parser.

func (*ArgClause) Enum Uses

func (p *ArgClause) Enum(options ...string) (target *string)

Enum allows a value from a set of options.

func (*ArgClause) EnumVar Uses

func (p *ArgClause) EnumVar(target *string, options ...string)

EnumVar allows a value from a set of options.

func (*ArgClause) Enums Uses

func (p *ArgClause) Enums(options ...string) (target *[]string)

Enums allows a set of values from a set of options.

func (*ArgClause) EnumsVar Uses

func (p *ArgClause) EnumsVar(target *[]string, options ...string)

EnumVar allows a value from a set of options.

func (*ArgClause) Envar Uses

func (a *ArgClause) Envar(name string) *ArgClause

Envar overrides the default value(s) for a flag from an environment variable, if it is set. Several default values can be provided by using new lines to separate them.

func (*ArgClause) ExistingDir Uses

func (p *ArgClause) ExistingDir() (target *string)

ExistingDir sets the parser to one that requires and returns an existing directory.

func (*ArgClause) ExistingDirVar Uses

func (p *ArgClause) ExistingDirVar(target *string)

ExistingDir sets the parser to one that requires and returns an existing directory.

func (*ArgClause) ExistingDirs Uses

func (p *ArgClause) ExistingDirs() (target *[]string)

ExistingDirs accumulates string values into a slice.

func (*ArgClause) ExistingDirsVar Uses

func (p *ArgClause) ExistingDirsVar(target *[]string)

func (*ArgClause) ExistingFile Uses

func (p *ArgClause) ExistingFile() (target *string)

ExistingFile sets the parser to one that requires and returns an existing file.

func (*ArgClause) ExistingFileOrDir Uses

func (p *ArgClause) ExistingFileOrDir() (target *string)

ExistingFileOrDir sets the parser to one that requires and returns an existing file OR directory.

func (*ArgClause) ExistingFileOrDirVar Uses

func (p *ArgClause) ExistingFileOrDirVar(target *string)

ExistingDir sets the parser to one that requires and returns an existing directory.

func (*ArgClause) ExistingFileVar Uses

func (p *ArgClause) ExistingFileVar(target *string)

ExistingFile sets the parser to one that requires and returns an existing file.

func (*ArgClause) ExistingFiles Uses

func (p *ArgClause) ExistingFiles() (target *[]string)

ExistingFiles accumulates string values into a slice.

func (*ArgClause) ExistingFilesOrDirs Uses

func (p *ArgClause) ExistingFilesOrDirs() (target *[]string)

ExistingFilesOrDirs accumulates string values into a slice.

func (*ArgClause) ExistingFilesOrDirsVar Uses

func (p *ArgClause) ExistingFilesOrDirsVar(target *[]string)

func (*ArgClause) ExistingFilesVar Uses

func (p *ArgClause) ExistingFilesVar(target *[]string)

func (*ArgClause) File Uses

func (p *ArgClause) File() (target **os.File)

File returns an os.File against an existing file.

func (*ArgClause) FileVar Uses

func (p *ArgClause) FileVar(target **os.File)

FileVar opens an existing file.

func (*ArgClause) Float Uses

func (p *ArgClause) Float() (target *float64)

Float sets the parser to a float64 parser.

func (*ArgClause) Float32 Uses

func (p *ArgClause) Float32() (target *float32)

Float32 parses the next command-line value as float32.

func (*ArgClause) Float32List Uses

func (p *ArgClause) Float32List() (target *[]float32)

Float32List accumulates float32 values into a slice.

func (*ArgClause) Float32ListVar Uses

func (p *ArgClause) Float32ListVar(target *[]float32)

func (*ArgClause) Float32Var Uses

func (p *ArgClause) Float32Var(target *float32)

func (*ArgClause) Float64 Uses

func (p *ArgClause) Float64() (target *float64)

Float64 parses the next command-line value as float64.

func (*ArgClause) Float64List Uses

func (p *ArgClause) Float64List() (target *[]float64)

Float64List accumulates float64 values into a slice.

func (*ArgClause) Float64ListVar Uses

func (p *ArgClause) Float64ListVar(target *[]float64)

func (*ArgClause) Float64Var Uses

func (p *ArgClause) Float64Var(target *float64)

func (*ArgClause) FloatVar Uses

func (p *ArgClause) FloatVar(target *float64)

Float sets the parser to a float64 parser.

func (*ArgClause) GetEnvarValue Uses

func (e *ArgClause) GetEnvarValue() string

func (*ArgClause) GetSplitEnvarValue Uses

func (e *ArgClause) GetSplitEnvarValue() []string

func (*ArgClause) HasEnvarValue Uses

func (e *ArgClause) HasEnvarValue() bool

func (*ArgClause) HexBytes Uses

func (p *ArgClause) HexBytes() (target *[]byte)

Bytes as a hex string.

func (*ArgClause) HexBytesList Uses

func (p *ArgClause) HexBytesList() (target *[][]byte)

HexBytesList accumulates []byte values into a slice.

func (*ArgClause) HexBytesListVar Uses

func (p *ArgClause) HexBytesListVar(target *[][]byte)

func (*ArgClause) HexBytesVar Uses

func (p *ArgClause) HexBytesVar(target *[]byte)

func (*ArgClause) HintAction Uses

func (a *ArgClause) HintAction(action HintAction) *ArgClause

HintAction registers a HintAction (function) for the arg to provide completions

func (*ArgClause) HintOptions Uses

func (a *ArgClause) HintOptions(options ...string) *ArgClause

HintOptions registers any number of options for the flag to provide completions

func (*ArgClause) IP Uses

func (p *ArgClause) IP() (target *net.IP)

IP sets the parser to a net.IP parser.

func (*ArgClause) IPList Uses

func (p *ArgClause) IPList() (target *[]net.IP)

IPList accumulates net.IP values into a slice.

func (*ArgClause) IPListVar Uses

func (p *ArgClause) IPListVar(target *[]net.IP)

func (*ArgClause) IPVar Uses

func (p *ArgClause) IPVar(target *net.IP)

IP sets the parser to a net.IP parser.

func (*ArgClause) Int Uses

func (p *ArgClause) Int() (target *int)

Int parses the next command-line value as int.

func (*ArgClause) Int16 Uses

func (p *ArgClause) Int16() (target *int16)

Int16 parses the next command-line value as int16.

func (*ArgClause) Int16List Uses

func (p *ArgClause) Int16List() (target *[]int16)

Int16List accumulates int16 values into a slice.

func (*ArgClause) Int16ListVar Uses

func (p *ArgClause) Int16ListVar(target *[]int16)

func (*ArgClause) Int16Var Uses

func (p *ArgClause) Int16Var(target *int16)

func (*ArgClause) Int32 Uses

func (p *ArgClause) Int32() (target *int32)

Int32 parses the next command-line value as int32.

func (*ArgClause) Int32List Uses

func (p *ArgClause) Int32List() (target *[]int32)

Int32List accumulates int32 values into a slice.

func (*ArgClause) Int32ListVar Uses

func (p *ArgClause) Int32ListVar(target *[]int32)

func (*ArgClause) Int32Var Uses

func (p *ArgClause) Int32Var(target *int32)

func (*ArgClause) Int64 Uses

func (p *ArgClause) Int64() (target *int64)

Int64 parses the next command-line value as int64.

func (*ArgClause) Int64List Uses

func (p *ArgClause) Int64List() (target *[]int64)

Int64List accumulates int64 values into a slice.

func (*ArgClause) Int64ListVar Uses

func (p *ArgClause) Int64ListVar(target *[]int64)

func (*ArgClause) Int64Var Uses

func (p *ArgClause) Int64Var(target *int64)

func (*ArgClause) Int8 Uses

func (p *ArgClause) Int8() (target *int8)

Int8 parses the next command-line value as int8.

func (*ArgClause) Int8List Uses

func (p *ArgClause) Int8List() (target *[]int8)

Int8List accumulates int8 values into a slice.

func (*ArgClause) Int8ListVar Uses

func (p *ArgClause) Int8ListVar(target *[]int8)

func (*ArgClause) Int8Var Uses

func (p *ArgClause) Int8Var(target *int8)

func (*ArgClause) IntVar Uses

func (p *ArgClause) IntVar(target *int)

func (*ArgClause) Ints Uses

func (p *ArgClause) Ints() (target *[]int)

Ints accumulates int values into a slice.

func (*ArgClause) IntsVar Uses

func (p *ArgClause) IntsVar(target *[]int)

func (*ArgClause) Model Uses

func (a *ArgClause) Model() *ArgModel

func (*ArgClause) NoEnvar Uses

func (a *ArgClause) NoEnvar() *ArgClause

NoEnvar forces environment variable defaults to be disabled for this flag. Most useful in conjunction with app.DefaultEnvars().

func (*ArgClause) OpenFile Uses

func (p *ArgClause) OpenFile(flag int, perm os.FileMode) (target **os.File)

File attempts to open a File with os.OpenFile(flag, perm).

func (*ArgClause) OpenFileVar Uses

func (p *ArgClause) OpenFileVar(target **os.File, flag int, perm os.FileMode)

OpenFileVar calls os.OpenFile(flag, perm)

func (*ArgClause) PreAction Uses

func (a *ArgClause) PreAction(action Action) *ArgClause

func (*ArgClause) Regexp Uses

func (p *ArgClause) Regexp() (target **regexp.Regexp)

Regexp parses the next command-line value as *regexp.Regexp.

func (*ArgClause) RegexpList Uses

func (p *ArgClause) RegexpList() (target *[]*regexp.Regexp)

RegexpList accumulates *regexp.Regexp values into a slice.

func (*ArgClause) RegexpListVar Uses

func (p *ArgClause) RegexpListVar(target *[]*regexp.Regexp)

func (*ArgClause) RegexpVar Uses

func (p *ArgClause) RegexpVar(target **regexp.Regexp)

func (*ArgClause) Required Uses

func (a *ArgClause) Required() *ArgClause

Required arguments must be input by the user. They can not have a Default() value provided.

func (*ArgClause) ResolvedIP Uses

func (p *ArgClause) ResolvedIP() (target *net.IP)

Resolve a hostname or IP to an IP.

func (*ArgClause) ResolvedIPList Uses

func (p *ArgClause) ResolvedIPList() (target *[]net.IP)

ResolvedIPList accumulates net.IP values into a slice.

func (*ArgClause) ResolvedIPListVar Uses

func (p *ArgClause) ResolvedIPListVar(target *[]net.IP)

func (*ArgClause) ResolvedIPVar Uses

func (p *ArgClause) ResolvedIPVar(target *net.IP)

func (*ArgClause) SetValue Uses

func (p *ArgClause) SetValue(value Value)

func (*ArgClause) String Uses

func (p *ArgClause) String() (target *string)

String parses the next command-line value as string.

func (*ArgClause) StringMap Uses

func (p *ArgClause) StringMap() (target *map[string]string)

StringMap provides key=value parsing into a map.

func (*ArgClause) StringMapVar Uses

func (p *ArgClause) StringMapVar(target *map[string]string)

StringMap provides key=value parsing into a map.

func (*ArgClause) StringVar Uses

func (p *ArgClause) StringVar(target *string)

func (*ArgClause) Strings Uses

func (p *ArgClause) Strings() (target *[]string)

Strings accumulates string values into a slice.

func (*ArgClause) StringsVar Uses

func (p *ArgClause) StringsVar(target *[]string)

func (*ArgClause) TCP Uses

func (p *ArgClause) TCP() (target **net.TCPAddr)

TCP (host:port) address.

func (*ArgClause) TCPList Uses

func (p *ArgClause) TCPList() (target *[]*net.TCPAddr)

TCPList accumulates *net.TCPAddr values into a slice.

func (*ArgClause) TCPListVar Uses

func (p *ArgClause) TCPListVar(target *[]*net.TCPAddr)

func (*ArgClause) TCPVar Uses

func (p *ArgClause) TCPVar(target **net.TCPAddr)

TCPVar (host:port) address.

func (*ArgClause) URL Uses

func (p *ArgClause) URL() (target **url.URL)

URL provides a valid, parsed url.URL.

func (*ArgClause) URLList Uses

func (p *ArgClause) URLList() (target *[]*url.URL)

URLList provides a parsed list of url.URL values.

func (*ArgClause) URLListVar Uses

func (p *ArgClause) URLListVar(target *[]*url.URL)

URLListVar provides a parsed list of url.URL values.

func (*ArgClause) URLVar Uses

func (p *ArgClause) URLVar(target **url.URL)

URL provides a valid, parsed url.URL.

func (*ArgClause) Uint Uses

func (p *ArgClause) Uint() (target *uint)

Uint parses the next command-line value as uint.

func (*ArgClause) Uint16 Uses

func (p *ArgClause) Uint16() (target *uint16)

Uint16 parses the next command-line value as uint16.

func (*ArgClause) Uint16List Uses

func (p *ArgClause) Uint16List() (target *[]uint16)

Uint16List accumulates uint16 values into a slice.

func (*ArgClause) Uint16ListVar Uses

func (p *ArgClause) Uint16ListVar(target *[]uint16)

func (*ArgClause) Uint16Var Uses

func (p *ArgClause) Uint16Var(target *uint16)

func (*ArgClause) Uint32 Uses

func (p *ArgClause) Uint32() (target *uint32)

Uint32 parses the next command-line value as uint32.

func (*ArgClause) Uint32List Uses

func (p *ArgClause) Uint32List() (target *[]uint32)

Uint32List accumulates uint32 values into a slice.

func (*ArgClause) Uint32ListVar Uses

func (p *ArgClause) Uint32ListVar(target *[]uint32)

func (*ArgClause) Uint32Var Uses

func (p *ArgClause) Uint32Var(target *uint32)

func (*ArgClause) Uint64 Uses

func (p *ArgClause) Uint64() (target *uint64)

Uint64 parses the next command-line value as uint64.

func (*ArgClause) Uint64List Uses

func (p *ArgClause) Uint64List() (target *[]uint64)

Uint64List accumulates uint64 values into a slice.

func (*ArgClause) Uint64ListVar Uses

func (p *ArgClause) Uint64ListVar(target *[]uint64)

func (*ArgClause) Uint64Var Uses

func (p *ArgClause) Uint64Var(target *uint64)

func (*ArgClause) Uint8 Uses

func (p *ArgClause) Uint8() (target *uint8)

Uint8 parses the next command-line value as uint8.

func (*ArgClause) Uint8List Uses

func (p *ArgClause) Uint8List() (target *[]uint8)

Uint8List accumulates uint8 values into a slice.

func (*ArgClause) Uint8ListVar Uses

func (p *ArgClause) Uint8ListVar(target *[]uint8)

func (*ArgClause) Uint8Var Uses

func (p *ArgClause) Uint8Var(target *uint8)

func (*ArgClause) UintVar Uses

func (p *ArgClause) UintVar(target *uint)

func (*ArgClause) Uints Uses

func (p *ArgClause) Uints() (target *[]uint)

Uints accumulates uint values into a slice.

func (*ArgClause) UintsVar Uses

func (p *ArgClause) UintsVar(target *[]uint)

type ArgGroupModel Uses

type ArgGroupModel struct {
    Args []*ArgModel
}

func (*ArgGroupModel) ArgSummary Uses

func (a *ArgGroupModel) ArgSummary() string

type ArgModel Uses

type ArgModel struct {
    Name     string
    Help     string
    Default  []string
    Envar    string
    Required bool
    Value    Value
}

func (*ArgModel) String Uses

func (a *ArgModel) String() string

type CmdClause Uses

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

A CmdClause is a single top-level command. It encapsulates a set of flags and either subcommands or positional arguments.

func Command Uses

func Command(name, help string) *CmdClause

Command adds a new command to the default parser.

func (*CmdClause) Action Uses

func (c *CmdClause) Action(action Action) *CmdClause

func (*CmdClause) Alias Uses

func (c *CmdClause) Alias(name string) *CmdClause

Add an Alias for this command.

func (*CmdClause) CmdCompletion Uses

func (c *CmdClause) CmdCompletion(context *ParseContext) []string

CmdCompletion returns completion options for arguments, if that's where parsing left off, or commands if there aren't any unsatisfied args.

func (*CmdClause) Command Uses

func (c *CmdClause) Command(name, help string) *CmdClause

Command adds a new sub-command.

func (*CmdClause) Default Uses

func (c *CmdClause) Default() *CmdClause

Default makes this command the default if commands don't match.

func (*CmdClause) FlagCompletion Uses

func (c *CmdClause) FlagCompletion(flagName string, flagValue string) (choices []string, flagMatch bool, optionMatch bool)

func (*CmdClause) FullCommand Uses

func (c *CmdClause) FullCommand() string

func (*CmdClause) Hidden Uses

func (c *CmdClause) Hidden() *CmdClause

func (*CmdClause) Model Uses

func (c *CmdClause) Model() *CmdModel

func (*CmdClause) PreAction Uses

func (c *CmdClause) PreAction(action Action) *CmdClause

func (*CmdClause) Validate Uses

func (c *CmdClause) Validate(validator CmdClauseValidator) *CmdClause

Validate sets a validation function to run when parsing.

type CmdClauseValidator Uses

type CmdClauseValidator func(*CmdClause) error

type CmdGroupModel Uses

type CmdGroupModel struct {
    Commands []*CmdModel
}

func (*CmdGroupModel) FlattenedCommands Uses

func (c *CmdGroupModel) FlattenedCommands() (out []*CmdModel)

type CmdModel Uses

type CmdModel struct {
    Name        string
    Aliases     []string
    Help        string
    FullCommand string
    Depth       int
    Hidden      bool
    Default     bool
    *FlagGroupModel
    *ArgGroupModel
    *CmdGroupModel
}

func (*CmdModel) String Uses

func (c *CmdModel) String() string

type FlagClause Uses

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

FlagClause is a fluid interface used to build flags.

func Flag Uses

func Flag(name, help string) *FlagClause

Flag adds a new flag to the default parser.

func (*FlagClause) Action Uses

func (f *FlagClause) Action(action Action) *FlagClause

Dispatch to the given function after the flag is parsed and validated.

func (*FlagClause) Bool Uses

func (f *FlagClause) Bool() (target *bool)

Bool makes this flag a boolean flag.

func (*FlagClause) BoolList Uses

func (p *FlagClause) BoolList() (target *[]bool)

BoolList accumulates bool values into a slice.

func (*FlagClause) BoolListVar Uses

func (p *FlagClause) BoolListVar(target *[]bool)

func (*FlagClause) BoolVar Uses

func (p *FlagClause) BoolVar(target *bool)

func (*FlagClause) Bytes Uses

func (p *FlagClause) Bytes() (target *units.Base2Bytes)

Bytes parses numeric byte units. eg. 1.5KB

func (*FlagClause) BytesVar Uses

func (p *FlagClause) BytesVar(target *units.Base2Bytes)

BytesVar parses numeric byte units. eg. 1.5KB

func (*FlagClause) Counter Uses

func (p *FlagClause) Counter() (target *int)

A Counter increments a number each time it is encountered.

func (*FlagClause) CounterVar Uses

func (p *FlagClause) CounterVar(target *int)

func (*FlagClause) Default Uses

func (f *FlagClause) Default(values ...string) *FlagClause

Default values for this flag. They *must* be parseable by the value of the flag.

func (*FlagClause) Duration Uses

func (p *FlagClause) Duration() (target *time.Duration)

Duration sets the parser to a time.Duration parser.

func (*FlagClause) DurationList Uses

func (p *FlagClause) DurationList() (target *[]time.Duration)

DurationList accumulates time.Duration values into a slice.

func (*FlagClause) DurationListVar Uses

func (p *FlagClause) DurationListVar(target *[]time.Duration)

func (*FlagClause) DurationVar Uses

func (p *FlagClause) DurationVar(target *time.Duration)

Duration sets the parser to a time.Duration parser.

func (*FlagClause) Enum Uses

func (a *FlagClause) Enum(options ...string) (target *string)

func (*FlagClause) EnumVar Uses

func (a *FlagClause) EnumVar(target *string, options ...string)

func (*FlagClause) Enums Uses

func (p *FlagClause) Enums(options ...string) (target *[]string)

Enums allows a set of values from a set of options.

func (*FlagClause) EnumsVar Uses

func (p *FlagClause) EnumsVar(target *[]string, options ...string)

EnumVar allows a value from a set of options.

func (*FlagClause) Envar Uses

func (f *FlagClause) Envar(name string) *FlagClause

Envar overrides the default value(s) for a flag from an environment variable, if it is set. Several default values can be provided by using new lines to separate them.

func (*FlagClause) ExistingDir Uses

func (p *FlagClause) ExistingDir() (target *string)

ExistingDir sets the parser to one that requires and returns an existing directory.

func (*FlagClause) ExistingDirVar Uses

func (p *FlagClause) ExistingDirVar(target *string)

ExistingDir sets the parser to one that requires and returns an existing directory.

func (*FlagClause) ExistingDirs Uses

func (p *FlagClause) ExistingDirs() (target *[]string)

ExistingDirs accumulates string values into a slice.

func (*FlagClause) ExistingDirsVar Uses

func (p *FlagClause) ExistingDirsVar(target *[]string)

func (*FlagClause) ExistingFile Uses

func (p *FlagClause) ExistingFile() (target *string)

ExistingFile sets the parser to one that requires and returns an existing file.

func (*FlagClause) ExistingFileOrDir Uses

func (p *FlagClause) ExistingFileOrDir() (target *string)

ExistingFileOrDir sets the parser to one that requires and returns an existing file OR directory.

func (*FlagClause) ExistingFileOrDirVar Uses

func (p *FlagClause) ExistingFileOrDirVar(target *string)

ExistingDir sets the parser to one that requires and returns an existing directory.

func (*FlagClause) ExistingFileVar Uses

func (p *FlagClause) ExistingFileVar(target *string)

ExistingFile sets the parser to one that requires and returns an existing file.

func (*FlagClause) ExistingFiles Uses

func (p *FlagClause) ExistingFiles() (target *[]string)

ExistingFiles accumulates string values into a slice.

func (*FlagClause) ExistingFilesOrDirs Uses

func (p *FlagClause) ExistingFilesOrDirs() (target *[]string)

ExistingFilesOrDirs accumulates string values into a slice.

func (*FlagClause) ExistingFilesOrDirsVar Uses

func (p *FlagClause) ExistingFilesOrDirsVar(target *[]string)

func (*FlagClause) ExistingFilesVar Uses

func (p *FlagClause) ExistingFilesVar(target *[]string)

func (*FlagClause) File Uses

func (p *FlagClause) File() (target **os.File)

File returns an os.File against an existing file.

func (*FlagClause) FileVar Uses

func (p *FlagClause) FileVar(target **os.File)

FileVar opens an existing file.

func (*FlagClause) Float Uses

func (p *FlagClause) Float() (target *float64)

Float sets the parser to a float64 parser.

func (*FlagClause) Float32 Uses

func (p *FlagClause) Float32() (target *float32)

Float32 parses the next command-line value as float32.

func (*FlagClause) Float32List Uses

func (p *FlagClause) Float32List() (target *[]float32)

Float32List accumulates float32 values into a slice.

func (*FlagClause) Float32ListVar Uses

func (p *FlagClause) Float32ListVar(target *[]float32)

func (*FlagClause) Float32Var Uses

func (p *FlagClause) Float32Var(target *float32)

func (*FlagClause) Float64 Uses

func (p *FlagClause) Float64() (target *float64)

Float64 parses the next command-line value as float64.

func (*FlagClause) Float64List Uses

func (p *FlagClause) Float64List() (target *[]float64)

Float64List accumulates float64 values into a slice.

func (*FlagClause) Float64ListVar Uses

func (p *FlagClause) Float64ListVar(target *[]float64)

func (*FlagClause) Float64Var Uses

func (p *FlagClause) Float64Var(target *float64)

func (*FlagClause) FloatVar Uses

func (p *FlagClause) FloatVar(target *float64)

Float sets the parser to a float64 parser.

func (*FlagClause) GetEnvarValue Uses

func (e *FlagClause) GetEnvarValue() string

func (*FlagClause) GetSplitEnvarValue Uses

func (e *FlagClause) GetSplitEnvarValue() []string

func (*FlagClause) HasEnvarValue Uses

func (e *FlagClause) HasEnvarValue() bool

func (*FlagClause) HexBytes Uses

func (p *FlagClause) HexBytes() (target *[]byte)

Bytes as a hex string.

func (*FlagClause) HexBytesList Uses

func (p *FlagClause) HexBytesList() (target *[][]byte)

HexBytesList accumulates []byte values into a slice.

func (*FlagClause) HexBytesListVar Uses

func (p *FlagClause) HexBytesListVar(target *[][]byte)

func (*FlagClause) HexBytesVar Uses

func (p *FlagClause) HexBytesVar(target *[]byte)

func (*FlagClause) Hidden Uses

func (f *FlagClause) Hidden() *FlagClause

Hidden hides a flag from usage but still allows it to be used.

func (*FlagClause) HintAction Uses

func (a *FlagClause) HintAction(action HintAction) *FlagClause

HintAction registers a HintAction (function) for the flag to provide completions

func (*FlagClause) HintOptions Uses

func (a *FlagClause) HintOptions(options ...string) *FlagClause

HintOptions registers any number of options for the flag to provide completions

func (*FlagClause) IP Uses

func (p *FlagClause) IP() (target *net.IP)

IP sets the parser to a net.IP parser.

func (*FlagClause) IPList Uses

func (p *FlagClause) IPList() (target *[]net.IP)

IPList accumulates net.IP values into a slice.

func (*FlagClause) IPListVar Uses

func (p *FlagClause) IPListVar(target *[]net.IP)

func (*FlagClause) IPVar Uses

func (p *FlagClause) IPVar(target *net.IP)

IP sets the parser to a net.IP parser.

func (*FlagClause) Int Uses

func (p *FlagClause) Int() (target *int)

Int parses the next command-line value as int.

func (*FlagClause) Int16 Uses

func (p *FlagClause) Int16() (target *int16)

Int16 parses the next command-line value as int16.

func (*FlagClause) Int16List Uses

func (p *FlagClause) Int16List() (target *[]int16)

Int16List accumulates int16 values into a slice.

func (*FlagClause) Int16ListVar Uses

func (p *FlagClause) Int16ListVar(target *[]int16)

func (*FlagClause) Int16Var Uses

func (p *FlagClause) Int16Var(target *int16)

func (*FlagClause) Int32 Uses

func (p *FlagClause) Int32() (target *int32)

Int32 parses the next command-line value as int32.

func (*FlagClause) Int32List Uses

func (p *FlagClause) Int32List() (target *[]int32)

Int32List accumulates int32 values into a slice.

func (*FlagClause) Int32ListVar Uses

func (p *FlagClause) Int32ListVar(target *[]int32)

func (*FlagClause) Int32Var Uses

func (p *FlagClause) Int32Var(target *int32)

func (*FlagClause) Int64 Uses

func (p *FlagClause) Int64() (target *int64)

Int64 parses the next command-line value as int64.

func (*FlagClause) Int64List Uses

func (p *FlagClause) Int64List() (target *[]int64)

Int64List accumulates int64 values into a slice.

func (*FlagClause) Int64ListVar Uses

func (p *FlagClause) Int64ListVar(target *[]int64)

func (*FlagClause) Int64Var Uses

func (p *FlagClause) Int64Var(target *int64)

func (*FlagClause) Int8 Uses

func (p *FlagClause) Int8() (target *int8)

Int8 parses the next command-line value as int8.

func (*FlagClause) Int8List Uses

func (p *FlagClause) Int8List() (target *[]int8)

Int8List accumulates int8 values into a slice.

func (*FlagClause) Int8ListVar Uses

func (p *FlagClause) Int8ListVar(target *[]int8)

func (*FlagClause) Int8Var Uses

func (p *FlagClause) Int8Var(target *int8)

func (*FlagClause) IntVar Uses

func (p *FlagClause) IntVar(target *int)

func (*FlagClause) Ints Uses

func (p *FlagClause) Ints() (target *[]int)

Ints accumulates int values into a slice.

func (*FlagClause) IntsVar Uses

func (p *FlagClause) IntsVar(target *[]int)

func (*FlagClause) Model Uses

func (f *FlagClause) Model() *FlagModel

func (*FlagClause) NoEnvar Uses

func (f *FlagClause) NoEnvar() *FlagClause

NoEnvar forces environment variable defaults to be disabled for this flag. Most useful in conjunction with app.DefaultEnvars().

func (*FlagClause) OpenFile Uses

func (p *FlagClause) OpenFile(flag int, perm os.FileMode) (target **os.File)

File attempts to open a File with os.OpenFile(flag, perm).

func (*FlagClause) OpenFileVar Uses

func (p *FlagClause) OpenFileVar(target **os.File, flag int, perm os.FileMode)

OpenFileVar calls os.OpenFile(flag, perm)

func (*FlagClause) OverrideDefaultFromEnvar Uses

func (f *FlagClause) OverrideDefaultFromEnvar(envar string) *FlagClause

DEPRECATED: Use Envar(name) instead.

func (*FlagClause) PlaceHolder Uses

func (f *FlagClause) PlaceHolder(placeholder string) *FlagClause

PlaceHolder sets the place-holder string used for flag values in the help. The default behaviour is to use the value provided by Default() if provided, then fall back on the capitalized flag name.

func (*FlagClause) PreAction Uses

func (f *FlagClause) PreAction(action Action) *FlagClause

func (*FlagClause) Regexp Uses

func (p *FlagClause) Regexp() (target **regexp.Regexp)

Regexp parses the next command-line value as *regexp.Regexp.

func (*FlagClause) RegexpList Uses

func (p *FlagClause) RegexpList() (target *[]*regexp.Regexp)

RegexpList accumulates *regexp.Regexp values into a slice.

func (*FlagClause) RegexpListVar Uses

func (p *FlagClause) RegexpListVar(target *[]*regexp.Regexp)

func (*FlagClause) RegexpVar Uses

func (p *FlagClause) RegexpVar(target **regexp.Regexp)

func (*FlagClause) Required Uses

func (f *FlagClause) Required() *FlagClause

Required makes the flag required. You can not provide a Default() value to a Required() flag.

func (*FlagClause) ResolvedIP Uses

func (p *FlagClause) ResolvedIP() (target *net.IP)

Resolve a hostname or IP to an IP.

func (*FlagClause) ResolvedIPList Uses

func (p *FlagClause) ResolvedIPList() (target *[]net.IP)

ResolvedIPList accumulates net.IP values into a slice.

func (*FlagClause) ResolvedIPListVar Uses

func (p *FlagClause) ResolvedIPListVar(target *[]net.IP)

func (*FlagClause) ResolvedIPVar Uses

func (p *FlagClause) ResolvedIPVar(target *net.IP)

func (*FlagClause) SetValue Uses

func (p *FlagClause) SetValue(value Value)

func (*FlagClause) Short Uses

func (f *FlagClause) Short(name rune) *FlagClause

Short sets the short flag name.

func (*FlagClause) String Uses

func (p *FlagClause) String() (target *string)

String parses the next command-line value as string.

func (*FlagClause) StringMap Uses

func (p *FlagClause) StringMap() (target *map[string]string)

StringMap provides key=value parsing into a map.

func (*FlagClause) StringMapVar Uses

func (p *FlagClause) StringMapVar(target *map[string]string)

StringMap provides key=value parsing into a map.

func (*FlagClause) StringVar Uses

func (p *FlagClause) StringVar(target *string)

func (*FlagClause) Strings Uses

func (p *FlagClause) Strings() (target *[]string)

Strings accumulates string values into a slice.

func (*FlagClause) StringsVar Uses

func (p *FlagClause) StringsVar(target *[]string)

func (*FlagClause) TCP Uses

func (p *FlagClause) TCP() (target **net.TCPAddr)

TCP (host:port) address.

func (*FlagClause) TCPList Uses

func (p *FlagClause) TCPList() (target *[]*net.TCPAddr)

TCPList accumulates *net.TCPAddr values into a slice.

func (*FlagClause) TCPListVar Uses

func (p *FlagClause) TCPListVar(target *[]*net.TCPAddr)

func (*FlagClause) TCPVar Uses

func (p *FlagClause) TCPVar(target **net.TCPAddr)

TCPVar (host:port) address.

func (*FlagClause) URL Uses

func (p *FlagClause) URL() (target **url.URL)

URL provides a valid, parsed url.URL.

func (*FlagClause) URLList Uses

func (p *FlagClause) URLList() (target *[]*url.URL)

URLList provides a parsed list of url.URL values.

func (*FlagClause) URLListVar Uses

func (p *FlagClause) URLListVar(target *[]*url.URL)

URLListVar provides a parsed list of url.URL values.

func (*FlagClause) URLVar Uses

func (p *FlagClause) URLVar(target **url.URL)

URL provides a valid, parsed url.URL.

func (*FlagClause) Uint Uses

func (p *FlagClause) Uint() (target *uint)

Uint parses the next command-line value as uint.

func (*FlagClause) Uint16 Uses

func (p *FlagClause) Uint16() (target *uint16)

Uint16 parses the next command-line value as uint16.

func (*FlagClause) Uint16List Uses

func (p *FlagClause) Uint16List() (target *[]uint16)

Uint16List accumulates uint16 values into a slice.

func (*FlagClause) Uint16ListVar Uses

func (p *FlagClause) Uint16ListVar(target *[]uint16)

func (*FlagClause) Uint16Var Uses

func (p *FlagClause) Uint16Var(target *uint16)

func (*FlagClause) Uint32 Uses

func (p *FlagClause) Uint32() (target *uint32)

Uint32 parses the next command-line value as uint32.

func (*FlagClause) Uint32List Uses

func (p *FlagClause) Uint32List() (target *[]uint32)

Uint32List accumulates uint32 values into a slice.

func (*FlagClause) Uint32ListVar Uses

func (p *FlagClause) Uint32ListVar(target *[]uint32)

func (*FlagClause) Uint32Var Uses

func (p *FlagClause) Uint32Var(target *uint32)

func (*FlagClause) Uint64 Uses

func (p *FlagClause) Uint64() (target *uint64)

Uint64 parses the next command-line value as uint64.

func (*FlagClause) Uint64List Uses

func (p *FlagClause) Uint64List() (target *[]uint64)

Uint64List accumulates uint64 values into a slice.

func (*FlagClause) Uint64ListVar Uses

func (p *FlagClause) Uint64ListVar(target *[]uint64)

func (*FlagClause) Uint64Var Uses

func (p *FlagClause) Uint64Var(target *uint64)

func (*FlagClause) Uint8 Uses

func (p *FlagClause) Uint8() (target *uint8)

Uint8 parses the next command-line value as uint8.

func (*FlagClause) Uint8List Uses

func (p *FlagClause) Uint8List() (target *[]uint8)

Uint8List accumulates uint8 values into a slice.

func (*FlagClause) Uint8ListVar Uses

func (p *FlagClause) Uint8ListVar(target *[]uint8)

func (*FlagClause) Uint8Var Uses

func (p *FlagClause) Uint8Var(target *uint8)

func (*FlagClause) UintVar Uses

func (p *FlagClause) UintVar(target *uint)

func (*FlagClause) Uints Uses

func (p *FlagClause) Uints() (target *[]uint)

Uints accumulates uint values into a slice.

func (*FlagClause) UintsVar Uses

func (p *FlagClause) UintsVar(target *[]uint)

type FlagGroupModel Uses

type FlagGroupModel struct {
    Flags []*FlagModel
}

func (*FlagGroupModel) FlagSummary Uses

func (f *FlagGroupModel) FlagSummary() string

type FlagModel Uses

type FlagModel struct {
    Name        string
    Help        string
    Short       rune
    Default     []string
    Envar       string
    PlaceHolder string
    Required    bool
    Hidden      bool
    Value       Value
}

func (*FlagModel) FormatPlaceHolder Uses

func (f *FlagModel) FormatPlaceHolder() string

func (*FlagModel) IsBoolFlag Uses

func (f *FlagModel) IsBoolFlag() bool

func (*FlagModel) String Uses

func (f *FlagModel) String() string

type Getter Uses

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

Getter is an interface that allows the contents of a Value to be retrieved. It wraps the Value interface, rather than being part of it, because it appeared after Go 1 and its compatibility rules. All Value types provided by this package satisfy the Getter interface.

type HintAction Uses

type HintAction func() []string

HintAction is a function type who is expected to return a slice of possible command line arguments.

type ParseContext Uses

type ParseContext struct {
    SelectedCommand *CmdClause

    // Flags, arguments and commands encountered and collected during parse.
    Elements []*ParseElement
    // contains filtered or unexported fields
}

ParseContext holds the current context of the parser. When passed to Action() callbacks Elements will be fully populated with *FlagClause, *ArgClause and *CmdClause values and their corresponding arguments (if any).

func (*ParseContext) EOL Uses

func (p *ParseContext) EOL() bool

func (*ParseContext) Error Uses

func (p *ParseContext) Error() bool

func (*ParseContext) HasTrailingArgs Uses

func (p *ParseContext) HasTrailingArgs() bool

HasTrailingArgs returns true if there are unparsed command-line arguments. This can occur if the parser can not match remaining arguments.

func (*ParseContext) Next Uses

func (p *ParseContext) Next() *Token

Next token in the parse context.

func (*ParseContext) Peek Uses

func (p *ParseContext) Peek() *Token

func (*ParseContext) Push Uses

func (p *ParseContext) Push(token *Token) *Token

func (*ParseContext) String Uses

func (p *ParseContext) String() string

type ParseElement Uses

type ParseElement struct {
    // Clause is either *CmdClause, *ArgClause or *FlagClause.
    Clause interface{}
    // Value is corresponding value for an ArgClause or FlagClause (if any).
    Value *string
}

A union of possible elements in a parse stack.

type Settings Uses

type Settings interface {
    SetValue(value Value)
}

type Token Uses

type Token struct {
    Index int
    Type  TokenType
    Value string
}

func (*Token) Equal Uses

func (t *Token) Equal(o *Token) bool

func (*Token) IsEOF Uses

func (t *Token) IsEOF() bool

func (*Token) IsFlag Uses

func (t *Token) IsFlag() bool

func (*Token) String Uses

func (t *Token) String() string

type TokenType Uses

type TokenType int
const (
    TokenShort TokenType = iota
    TokenLong
    TokenArg
    TokenError
    TokenEOL
)

Token types.

func (TokenType) String Uses

func (t TokenType) String() string

type Value Uses

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

If a Value has an IsBoolFlag() bool method returning true, the command-line parser makes --name equivalent to -name=true rather than using the next command-line argument, and adds a --no-name counterpart for negating the flag.

This example ilustrates how to define custom parsers. HTTPHeader cumulatively parses each encountered --header flag into a http.Header struct.

Code:

package main

import (
    "fmt"
    "net/http"
    "strings"
)

type HTTPHeaderValue http.Header

func (h *HTTPHeaderValue) Set(value string) error {
    parts := strings.SplitN(value, ":", 2)
    if len(parts) != 2 {
        return fmt.Errorf("expected HEADER:VALUE got '%s'", value)
    }
    (*http.Header)(h).Add(parts[0], parts[1])
    return nil
}

func (h *HTTPHeaderValue) Get() interface{} {
    return (http.Header)(*h)
}

func (h *HTTPHeaderValue) String() string {
    return ""
}

func HTTPHeader(s Settings) (target *http.Header) {
    target = new(http.Header)
    s.SetValue((*HTTPHeaderValue)(target))
    return
}

// This example ilustrates how to define custom parsers. HTTPHeader
// cumulatively parses each encountered --header flag into a http.Header struct.
func main() {
    var (
        curl    = New("curl", "transfer a URL")
        headers = HTTPHeader(curl.Flag("headers", "Add HTTP headers to the request.").Short('H').PlaceHolder("HEADER:VALUE"))
    )

    curl.Parse([]string{"-H Content-Type:application/octet-stream"})
    for key, value := range *headers {
        fmt.Printf("%s = %s\n", key, value)
    }
}

Directories

PathSynopsis
cmd/genvalues

Package kingpin imports 20 packages (graph) and is imported by 1168 packages. Updated 2019-09-22. Refresh now. Tools for package owners.