Categorygithub.com/alecthomas/kong
modulepackage
1.8.1
Repository: https://github.com/alecthomas/kong.git
Documentation: pkg.go.dev

# README

Kong is a command-line parser for Go

CircleCI Go Report Card Slack chat

Version 1.0.0 Release

Kong has been stable for a long time, so it seemed appropriate to cut a 1.0 release.

There is one breaking change, #436, which should effect relatively few users.

Introduction

Kong aims to support arbitrarily complex command-line structures with as little developer effort as possible.

To achieve that, command-lines are expressed as Go types, with the structure and tags directing how the command line is mapped onto the struct.

For example, the following command-line:

shell rm [-f] [-r] <paths> ...
shell ls [<paths> ...]

Can be represented by the following command-line structure:

package main

import "github.com/alecthomas/kong"

var CLI struct {
  Rm struct {
    Force     bool `help:"Force removal."`
    Recursive bool `help:"Recursively remove files."`

    Paths []string `arg:"" name:"path" help:"Paths to remove." type:"path"`
  } `cmd:"" help:"Remove files."`

  Ls struct {
    Paths []string `arg:"" optional:"" name:"path" help:"Paths to list." type:"path"`
  } `cmd:"" help:"List paths."`
}

func main() {
  ctx := kong.Parse(&CLI)
  switch ctx.Command() {
  case "rm <path>":
  case "ls":
  default:
    panic(ctx.Command())
  }
}

Help

Help as a user of a Kong application

Every Kong application includes a --help flag that will display auto-generated help.

eg.

$ shell --help
usage: shell <command>

A shell-like example app.

Flags:
  --help   Show context-sensitive help.
  --debug  Debug mode.

Commands:
  rm <path> ...
    Remove files.

  ls [<path> ...]
    List paths.

If a command is provided, the help will show full detail on the command including all available flags.

eg.

$ shell --help rm
usage: shell rm <paths> ...

Remove files.

Arguments:
  <paths> ...  Paths to remove.

Flags:
      --debug        Debug mode.

  -f, --force        Force removal.
  -r, --recursive    Recursively remove files.

Defining help in Kong

Help is automatically generated from the command-line structure itself, including help:"" and other tags. Variables will also be interpolated into the help string.

Finally, any command, or argument type implementing the interface Help() string will have this function called to retrieve more detail to augment the help tag. This allows for much more descriptive text than can fit in Go tags. See _examples/shell/help

Showing the command's detailed help

A command's additional help text is not shown from top-level help, but can be displayed within contextual help:

Top level help

 $ go run ./_examples/shell/help --help
Usage: help <command>

An app demonstrating HelpProviders

Flags:
  -h, --help    Show context-sensitive help.
      --flag    Regular flag help

Commands:
  echo    Regular command help

Contextual

 $ go run ./_examples/shell/help echo --help
Usage: help echo <msg>

Regular command help

🚀 additional command help

Arguments:
  <msg>    Regular argument help

Flags:
  -h, --help    Show context-sensitive help.
      --flag    Regular flag help

Showing an argument's detailed help

Custom help will only be shown for positional arguments with named fields (see the README section on positional arguments for more details on what that means)

Contextual argument help

 $ go run ./_examples/shell/help msg --help
Usage: help echo <msg>

Regular argument help

📣 additional argument help

Flags:
  -h, --help    Show context-sensitive help.
      --flag    Regular flag help

Command handling

There are two ways to handle commands in Kong.

Switch on the command string

When you call kong.Parse() it will return a unique string representation of the command. Each command branch in the hierarchy will be a bare word and each branching argument or required positional argument will be the name surrounded by angle brackets. Here's an example:

There's an example of this pattern here.

eg.

package main

import "github.com/alecthomas/kong"

var CLI struct {
  Rm struct {
    Force     bool `help:"Force removal."`
    Recursive bool `help:"Recursively remove files."`

    Paths []string `arg:"" name:"path" help:"Paths to remove." type:"path"`
  } `cmd:"" help:"Remove files."`

  Ls struct {
    Paths []string `arg:"" optional:"" name:"path" help:"Paths to list." type:"path"`
  } `cmd:"" help:"List paths."`
}

func main() {
  ctx := kong.Parse(&CLI)
  switch ctx.Command() {
  case "rm <path>":
  case "ls":
  default:
    panic(ctx.Command())
  }
}

This has the advantage that it is convenient, but the downside that if you modify your CLI structure, the strings may change. This can be fragile.

Attach a Run(...) error method to each command

A more robust approach is to break each command out into their own structs:

  1. Break leaf commands out into separate structs.
  2. Attach a Run(...) error method to all leaf commands.
  3. Call kong.Kong.Parse() to obtain a kong.Context.
  4. Call kong.Context.Run(bindings...) to call the selected parsed command.

Once a command node is selected by Kong it will search from that node back to the root. Each encountered command node with a Run(...) error will be called in reverse order. This allows sub-trees to be re-used fairly conveniently.

In addition to values bound with the kong.Bind(...) option, any values passed through to kong.Context.Run(...) are also bindable to the target's Run() arguments.

Finally, hooks can also contribute bindings via kong.Context.Bind() and kong.Context.BindTo().

There's a full example emulating part of the Docker CLI here.

eg.

type Context struct {
  Debug bool
}

type RmCmd struct {
  Force     bool `help:"Force removal."`
  Recursive bool `help:"Recursively remove files."`

  Paths []string `arg:"" name:"path" help:"Paths to remove." type:"path"`
}

func (r *RmCmd) Run(ctx *Context) error {
  fmt.Println("rm", r.Paths)
  return nil
}

type LsCmd struct {
  Paths []string `arg:"" optional:"" name:"path" help:"Paths to list." type:"path"`
}

func (l *LsCmd) Run(ctx *Context) error {
  fmt.Println("ls", l.Paths)
  return nil
}

var cli struct {
  Debug bool `help:"Enable debug mode."`

  Rm RmCmd `cmd:"" help:"Remove files."`
  Ls LsCmd `cmd:"" help:"List paths."`
}

func main() {
  ctx := kong.Parse(&cli)
  // Call the Run() method of the selected parsed command.
  err := ctx.Run(&Context{Debug: cli.Debug})
  ctx.FatalIfErrorf(err)
}

Hooks: BeforeReset(), BeforeResolve(), BeforeApply(), AfterApply()

If a node in the CLI, or any of its embedded fields, has a BeforeReset(...) error, BeforeResolve (...) error, BeforeApply(...) error and/or AfterApply(...) error method, those methods will be called before values are reset, before validation/assignment, and after validation/assignment, respectively.

The --help flag is implemented with a BeforeReset hook.

eg.

// A flag with a hook that, if triggered, will set the debug loggers output to stdout.
type debugFlag bool

func (d debugFlag) BeforeApply(logger *log.Logger) error {
  logger.SetOutput(os.Stdout)
  return nil
}

var cli struct {
  Debug debugFlag `help:"Enable debug logging."`
}

func main() {
  // Debug logger going to discard.
  logger := log.New(io.Discard, "", log.LstdFlags)

  ctx := kong.Parse(&cli, kong.Bind(logger))

  // ...
}

The Bind() option

Arguments to hooks are provided via the Run(...) method or Bind(...) option. *Kong, *Context, *Path and parent commands are also bound and finally, hooks can also contribute bindings via kong.Context.Bind() and kong.Context.BindTo().

eg:

type CLI struct {
  Debug bool `help:"Enable debug mode."`

  Rm RmCmd `cmd:"" help:"Remove files."`
  Ls LsCmd `cmd:"" help:"List paths."`
}

type AuthorName string

// ...
func (l *LsCmd) Run(cli *CLI) error {
// use cli.Debug here !!
  return nil
}

func (r *RmCmD) Run(author AuthorName) error{
// use binded author here
  return nil
}

func main() {
  var cli CLI
  
  ctx := kong.Parse(&cli, Bind(AuthorName("penguin")))
  err := ctx.Run()

Flags

Any mapped field in the command structure not tagged with cmd or arg will be a flag. Flags are optional by default.

eg. The command-line app [--flag="foo"] can be represented by the following.

type CLI struct {
  Flag string
}

Commands and sub-commands

Sub-commands are specified by tagging a struct field with cmd. Kong supports arbitrarily nested commands.

eg. The following struct represents the CLI structure command [--flag="str"] sub-command.

type CLI struct {
  Command struct {
    Flag string

    SubCommand struct {
    } `cmd`
  } `cmd`
}

If a sub-command is tagged with default:"1" it will be selected if there are no further arguments. If a sub-command is tagged with default:"withargs" it will be selected even if there are further arguments or flags and those arguments or flags are valid for the sub-command. This allows the user to omit the sub-command name on the CLI if its arguments/flags are not ambiguous with the sibling commands or flags.

Branching positional arguments

In addition to sub-commands, structs can also be configured as branching positional arguments.

This is achieved by tagging an unmapped nested struct field with arg, then including a positional argument field inside that struct with the same name. For example, the following command structure:

app rename <name> to <name>

Can be represented with the following:

var CLI struct {
  Rename struct {
    Name struct {
      Name string `arg` // <-- NOTE: identical name to enclosing struct field.
      To struct {
        Name struct {
          Name string `arg`
        } `arg`
      } `cmd`
    } `arg`
  } `cmd`
}

This looks a little verbose in this contrived example, but typically this will not be the case.

Positional arguments

If a field is tagged with arg:"" it will be treated as the final positional value to be parsed on the command line. By default positional arguments are required, but specifying optional:"" will alter this.

If a positional argument is a slice, all remaining arguments will be appended to that slice.

Slices

Slice values are treated specially. First the input is split on the sep:"<rune>" tag (defaults to ,), then each element is parsed by the slice element type and appended to the slice. If the same value is encountered multiple times, elements continue to be appended.

To represent the following command-line:

cmd ls <file> <file> ...

You would use the following:

var CLI struct {
  Ls struct {
    Files []string `arg:"" type:"existingfile"`
  } `cmd`
}

Maps

Maps are similar to slices except that only one key/value pair can be assigned per value, and the sep tag denotes the assignment character and defaults to =.

To represent the following command-line:

cmd config set <key>=<value> <key>=<value> ...

You would use the following:

var CLI struct {
  Config struct {
    Set struct {
      Config map[string]float64 `arg:"" type:"file:"`
    } `cmd`
  } `cmd`
}

For flags, multiple key+value pairs should be separated by mapsep:"rune" tag (defaults to ;) eg. --set="key1=value1;key2=value2".

Pointers

Pointers work like the underlying type, except that you can differentiate between the presence of the zero value and no value being supplied.

For example:

var CLI struct {
	Foo *int
}

Would produce a nil value for Foo if no --foo argument is supplied, but would have a pointer to the value 0 if the argument --foo=0 was supplied.

Nested data structure

Kong support a nested data structure as well with embed:"". You can combine embed:"" with prefix:"":

var CLI struct {
  Logging struct {
    Level string `enum:"debug,info,warn,error" default:"info"`
    Type string `enum:"json,console" default:"console"`
  } `embed:"" prefix:"logging."`
}

This configures Kong to accept flags --logging.level and --logging.type.

Custom named decoders

Kong includes a number of builtin custom type mappers. These can be used by specifying the tag type:"<type>". They are registered with the option function NamedMapper(name, mapper).

NameDescription
pathA path. ~ expansion is applied. - is accepted for stdout, and will be passed unaltered.
existingfileAn existing file. ~ expansion is applied. - is accepted for stdin, and will be passed unaltered.
existingdirAn existing directory. ~ expansion is applied.
counterIncrement a numeric field. Useful for -vvv. Can accept -s, --long or --long=N.
filecontentRead the file at path into the field. ~ expansion is applied. - is accepted for stdin, and will be passed unaltered.

Slices and maps treat type tags specially. For slices, the type:"" tag specifies the element type. For maps, the tag has the format tag:"[<key>]:[<value>]" where either may be omitted.

Supported field types

Custom decoders (mappers)

Any field implementing encoding.TextUnmarshaler or json.Unmarshaler will use those interfaces for decoding values. Kong also includes builtin support for many common Go types:

TypeDescription
time.DurationPopulated using time.ParseDuration().
time.TimePopulated using time.Parse(). Format defaults to RFC3339 but can be overridden with the format:"X" tag.
*os.FilePath to a file that will be opened, or - for os.Stdin. File must be closed by the user.
*url.URLPopulated with url.Parse().

For more fine-grained control, if a field implements the MapperValue interface it will be used to decode arguments into the field.

Supported tags

Tags can be in two forms:

  1. Standard Go syntax, eg. kong:"required,name='foo'".
  2. Bare tags, eg. required:"" name:"foo"

Both can coexist with standard Tag parsing.

TagDescription
cmd:""If present, struct is a command.
arg:""If present, field is an argument. Required by default.
env:"X,Y,..."Specify envars to use for default value. The envs are resolved in the declared order. The first value found is used.
name:"X"Long name, for overriding field name.
help:"X"Help text.
type:"X"Specify named types to use.
placeholder:"X"Placeholder input, if flag. e.g. `placeholder:"<the-placeholder>"` will show --flag-name=<the-placeholder> when displaying help.
default:"X"Default value.
default:"1"On a command, make it the default.
default:"withargs"On a command, make it the default and allow args/flags from that command
short:"X"Short name, if flag.
aliases:"X,Y"One or more aliases (for cmd or flag).
required:""If present, flag/arg is required.
optional:""If present, flag/arg is optional.
hidden:""If present, command or flag is hidden.
negatable:""If present on a bool field, supports prefixing a flag with --no- to invert the default value
negatable:"X"If present on a bool field, supports --X to invert the default value
format:"X"Format for parsing input, if supported.
sep:"X"Separator for sequences (defaults to ","). May be none to disable splitting.
mapsep:"X"Separator for maps (defaults to ";"). May be none to disable splitting.
enum:"X,Y,..."Set of valid values allowed for this flag. An enum field must be required or have a valid default.
group:"X"Logical group for a flag or command.
xor:"X,Y,..."Exclusive OR groups for flags. Only one flag in the group can be used which is restricted within the same command. When combined with required, at least one of the xor group will be required.
and:"X,Y,..."AND groups for flags. All flags in the group must be used in the same command. When combined with required, all flags in the group will be required.
prefix:"X"Prefix for all sub-flags.
envprefix:"X"Envar prefix for all sub-flags.
xorprefix:"X"Prefix for all sub-flags in XOR/AND groups.
set:"K=V"Set a variable for expansion by child elements. Multiples can occur.
embed:""If present, this field's children will be embedded in the parent. Useful for composition.
passthrough:"<mode>"1If present on a positional argument, it stops flag parsing when encountered, as if -- was processed before. Useful for external command wrappers, like exec. On a command it requires that the command contains only one argument of type []string which is then filled with everything following the command, unparsed.
-Ignore the field. Useful for adding non-CLI fields to a configuration struct. e.g `kong:"-"`

Plugins

Kong CLI's can be extended by embedding the kong.Plugin type and populating it with pointers to Kong annotated structs. For example:

var pluginOne struct {
  PluginOneFlag string
}
var pluginTwo struct {
  PluginTwoFlag string
}
var cli struct {
  BaseFlag string
  kong.Plugins
}
cli.Plugins = kong.Plugins{&pluginOne, &pluginTwo}

Additionally if an interface type is embedded, it can also be populated with a Kong annotated struct.

Dynamic Commands

While plugins give complete control over extending command-line interfaces, Kong also supports dynamically adding commands via kong.DynamicCommand().

Variable interpolation

Kong supports limited variable interpolation into help strings, enum lists and default values.

Variables are in the form:

${<name>}
${<name>=<default>}

Variables are set with the Vars{"key": "value", ...} option. Undefined variable references in the grammar without a default will result in an error at construction time.

Variables can also be set via the set:"K=V" tag. In this case, those variables will be available for that node and all children. This is useful for composition by allowing the same struct to be reused.

When interpolating into flag or argument help strings, some extra variables are defined from the value itself:

${default}
${enum}

For flags with associated environment variables, the variable ${env} can be interpolated into the help string. In the absence of this variable in the help string, Kong will append ($$${env}) to the help string.

eg.

type cli struct {
  Config string `type:"path" default:"${config_file}"`
}

func main() {
  kong.Parse(&cli,
    kong.Vars{
      "config_file": "~/.app.conf",
    })
}

Validation

Kong does validation on the structure of a command-line, but also supports extensible validation. Any node in the tree may implement either of the following interfaces:

type Validatable interface {
    Validate() error
 }
type Validatable interface {
    Validate(kctx *kong.Context) error
 }

If one of these nodes is in the active command-line it will be called during normal validation.

Modifying Kong's behaviour

Each Kong parser can be configured via functional options passed to New(cli any, options...Option).

The full set of options can be found here.

Name(help) and Description(help) - set the application name description

Set the application name and/or description.

The name of the application will default to the binary name, but can be overridden with Name(name).

As with all help in Kong, text will be wrapped to the terminal.

Configuration(loader, paths...) - load defaults from configuration files

This option provides Kong with support for loading defaults from a set of configuration files. Each file is opened, if possible, and the loader called to create a resolver for that file.

eg.

kong.Parse(&cli, kong.Configuration(kong.JSON, "/etc/myapp.json", "~/.myapp.json"))

See the tests for an example of how the JSON file is structured.

List of Configuration Loaders

Resolver(...) - support for default values from external sources

Resolvers are Kong's extension point for providing default values from external sources. As an example, support for environment variables via the env tag is provided by a resolver. There's also a builtin resolver for JSON configuration files.

Example resolvers can be found in resolver.go.

*Mapper(...) - customising how the command-line is mapped to Go values

Command-line arguments are mapped to Go values via the Mapper interface:

// A Mapper represents how a field is mapped from command-line values to Go.
//
// Mappers can be associated with concrete fields via pointer, reflect.Type, reflect.Kind, or via a "type" tag.
//
// Additionally, if a type implements the MapperValue interface, it will be used.
type Mapper interface {
	// Decode ctx.Value with ctx.Scanner into target.
	Decode(ctx *DecodeContext, target reflect.Value) error
}

All builtin Go types (as well as a bunch of useful stdlib types like time.Time) have mappers registered by default. Mappers for custom types can be added using kong.??Mapper(...) options. Mappers are applied to fields in four ways:

  1. NamedMapper(string, Mapper) and using the tag key type:"<name>".
  2. KindMapper(reflect.Kind, Mapper).
  3. TypeMapper(reflect.Type, Mapper).
  4. ValueMapper(any, Mapper), passing in a pointer to a field of the grammar.

ConfigureHelp(HelpOptions) and Help(HelpFunc) - customising help

The default help output is usually sufficient, but if not there are two solutions.

  1. Use ConfigureHelp(HelpOptions) to configure how help is formatted (see HelpOptions for details).
  2. Custom help can be wired into Kong via the Help(HelpFunc) option. The HelpFunc is passed a Context, which contains the parsed context for the current command-line. See the implementation of DefaultHelpPrinter for an example.
  3. Use ValueFormatter(HelpValueFormatter) if you want to just customize the help text that is accompanied by flags and arguments.
  4. Use Groups([]Group) if you want to customize group titles or add a header.

Injecting values into Run() methods

There are several ways to inject values into Run() methods:

  1. Use Bind() to bind values directly.
  2. Use BindTo() to bind values to an interface type.
  3. Use BindToProvider() to bind values to a function that provides the value.
  4. Implement Provide<Type>() error methods on the command structure.

Other options

The full set of options can be found here.

Footnotes

  1. <mode> can be partial or all (the default). all will pass through all arguments including flags, including flags. partial will validate flags until the first positional argument is encountered, then pass through all remaining positional arguments. ↩

# Functions

ApplyDefaults if they are not already set.
AutoGroup automatically assigns groups to flags.
Bind binds values for hooks and Run() function arguments.
BindTo allows binding of implementations to interfaces.
BindToProvider binds an injected value to a provider function.
ClearResolvers clears all existing resolvers.
Configuration provides Kong with support for loading defaults from a set of configuration files.
ConfigureHelp sets the HelpOptions to use for printing help.
DefaultEnvars option inits environment names for flags.
DefaultHelpPrinter is the default HelpPrinter.
DefaultHelpValueFormatter is the default HelpValueFormatter.
DefaultShortHelpPrinter is the default HelpPrinter for short help on error.
Description sets the application description.
DynamicCommand registers a dynamically constructed command with the root of the CLI.
Embed a struct into the root of the CLI.
Exit overrides the function used to terminate.
ExpandPath is a helper function to expand a relative or home-relative path to an absolute path.
ExplicitGroups associates `group` field tags with their metadata.
FlagNamer allows you to override the default kebab-case automated flag name generation.
HasInterpolatedVar returns true if the variable "v" is interpolated in "s".
Help printer to use.
HelpFormatter configures how the help text is formatted.
IgnoreFields will cause kong.New() to skip field names that match any of the provided regex patterns.
JoinEscaped joins a slice of strings on sep, but also escapes any instances of sep in the fields with \.
JSON returns a Resolver that retrieves values from a JSON source.
KindMapper registers a mapper to a kind.
LineIndenter adds line points to every new indent.
Must creates a new Parser or panics if there is an error.
Name overrides the application name.
NamedMapper registers a mapper to a name.
New creates a new Kong parser on grammar.
NewRegistry creates a new (empty) Registry.
NoDefaultHelp disables the default help flags.
Parse constructs a new parser and parses the default command-line.
PostBuild provides read/write access to kong.Kong after initial construction of the model is complete but before parsing occurs.
Resolvers registers flag resolvers.
Scan creates a new Scanner from args with untyped tokens.
ScanAsType creates a new Scanner from args with the given type.
ScanFromTokens creates a new Scanner from a slice of tokens.
ShortHelp configures the short usage message.
ShortUsageOnError configures Kong to display context-sensitive short usage if FatalIfErrorf is called with an error.
SpaceIndenter adds a space indent to the given prefix.
SplitEscaped splits a string on a separator.
Trace path of "args" through the grammar tree.
TreeIndenter adds line points to every new indent and vertical lines to every layer.
TypeMapper registers a mapper to a type.
UsageOnError configures Kong to display context-sensitive usage if FatalIfErrorf is called with an error.
ValueFormatter configures how the help text is formatted.
ValueMapper registers a mapper to a field value.
Visit all nodes.
Writers overrides the default writers.

# Constants

Node type enumerations.
Node type enumerations.
Node type enumerations.
Token types.
--<flag>.
=<value>.
PassThroughModeAll indicates that all parameters, including flags, are passed through.
PassThroughModeNone indicates passthrough mode is disabled.
PassThroughModePartial will validate flags until the first positional argument is encountered, then pass through all remaining positional arguments.
<arg>.
<tail>.
-<short>[<tail].
Token types.

# Structs

Application is the root of the Kong model.
Context contains the current parse context.
DecodeContext is passed to a Mapper's Decode().
A Flag represents a command-line flag.
Group holds metadata about a command or flag group used when printing help.
HelpOptions for HelpPrinters.
Kong is the main parser type.
NamedFileContentFlag is a flag value that loads a file's contents and filename into its value.
Node is a branch in the CLI.
ParseError is the error type returned by Kong.Parse().
Path records the nodes and parsed values from the current command-line.
A Registry contains a set of mappers and supporting lookup methods.
Scanner is a stack-based scanner over command-line tokens.
Tag represents the parsed state of Kong tags in a struct field tag.
Token created by Scanner.
A Value is either a flag or a variable positional argument.

# Interfaces

AfterApply is a documentation-only interface describing hooks that run after values are set.
AfterRun is a documentation-only interface describing hooks that run after Run() returns.
BeforeApply is a documentation-only interface describing hooks that run before values are set.
BeforeResolve is a documentation-only interface describing hooks that run before resolvers are applied.
A BoolMapper is a Mapper to a value that is a boolean.
BoolMapperExt allows a Mapper to dynamically determine if a value is a boolean.
BoolMapperValue may be implemented by fields in order to provide custom mappings for boolean values.
HelpProvider can be implemented by commands/args to provide detailed help.
A Mapper represents how a field is mapped from command-line values to Go.
MapperValue may be implemented by fields in order to provide custom mapping.
An Option applies optional changes to the Kong application.
PlaceHolderProvider can be implemented by mappers to provide custom placeholder text.
A Resolver resolves a Flag value from an external source.
VarsContributor can be implemented by a Mapper to contribute Vars during interpolation.
A Visitable component in the model.

# Type aliases

Argument represents a branching positional argument.
ChangeDirFlag changes the current working directory to a path specified by a flag early in the parsing process, changing how other flags resolve relative paths.
Command represents a command in the CLI.
ConfigFlag uses the configured (via kong.Configuration(loader)) configuration loader to load configuration from a file specified by a flag.
ConfigurationLoader is a function that builds a resolver from a file.
FileContentFlag is a flag value that loads a file's contents into its value.
Groups associates `group` field tags with group metadata.
HelpIndenter is used to indent new layers in the help tree.
HelpPrinter is used to print context-sensitive help.
HelpValueFormatter is used to format the help text of flags and positional arguments.
A MapperFunc is a single function that complies with the Mapper interface.
Next should be called by Visitor to proceed with the walk.
NodeType is an enum representing the type of a Node.
OptionFunc is function that adheres to the Option interface.
PassthroughMode indicates how parameters are passed through when "passthrough" is set.
Plugins are dynamically embedded command-line structures.
A Positional represents a non-branching command-line positional argument.
ResolverFunc is a convenience type for non-validating Resolvers.
TokenType is the type of a token.
Vars sets the variables to use for interpolation into help strings and default values.
VersionFlag is a flag type that can be used to display a version number, stored in the "version" variable.
Visitor can be used to walk all nodes in the model.