Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action int
Suggested action after parsing.
const ( // Proceed to Run(...) the command. Exit 0 if Run(...) returns true, nonzero // otherwise. Proceed Action = iota // Display help. The user explicitly requested it, so exit 0. HelpOK // Display help. The user didn't request it (or requested it wonkily) so // exit nonzero. HelpError // Nothing more to do. Exit nonzero. Fatal )
type App ¶
type App struct {
// Headline of the app, displayed at the top of help output.
//
// Note that unlike Command.Headline, this is displayed above *everything*,
// and in all help output (regardless of command). It also won't be
// formatted in the same way ({} won't be highlighted).
Headline string
// Long description of the app, displayed below usage in help output. Should
// both start and end with a newline \n.
//
// This is usually a long, multiline string. Rather the inlining this string
// to an App literal, it's recommended to create a raw const string
// elsewhere and use that instead, putting each backtick on its own line.
// See the examples.
//
// Text inside {curly braces} will be highlighted.
Description string
// The app's commands, in order of display in help output.
Commands []Command
// Name of the command to run if none is supplied. Leave blank to require
// one.
DefaultCommand string
// Highlight color in help output.
HighlightColor color.Attribute
}
CLI application configuration.
type Args ¶
type Args struct {
// Number of expected positional args. If Varadic is set, this is the
// *minimum* number of positional args.
Count int
// Whether to accept more args than specified in Count.
Varadic bool
// Sets term(s) for the args. These are displayed in the usage line at the
// top of help. They should be uppercase. '[--]' will be prepended, and
// names will be [bracketed] appropriately if Varadic is set.
Metavars []string
}
Configuration for positional arguments.
type Command ¶
type Command struct {
// Name of the command that the user will need to specify.
Name string
// Summary of the command. Displayed in help, below 'Usage:'.
//
// Text inside {curly braces} will be highlighted.
Headline string
// Long description of the command, displayed below usage in help output.
// Should both start and end with a newline \n.
//
// This is usually a long, multiline string. Rather the inlining this string
// to a Command literal, it's recommended to create a raw const string
// elsewhere and use that instead, putting each backtick on its own line.
// See the examples.
//
// Text inside {curly braces} will be highlighted.
Description string
// This command's options, in order of display in help output.
Options []Option
// This command's trailing arguments. It's safe to leave this blank if you
// don't have any.
Args Args
// Function to run if this Command is chosen.
//
// This is expected to further validate each option's values, *appending* to
// r.Errs. If r.Errs has any members by the end of validation, it should
// return false before proceeding with its business. At this point, it can
// stop appending to r.Errs, but should only return true if the operation
// succeeded overall.
//
// The caller should inspect r.Errs after this function returns, and exit
// the program nonzero if it returned false.
Run func(r *Result) bool
}
Configuration for a single CLI (sub-)command.
type Option ¶
type Option struct {
// Short option name, used for single-dashed args (like '-a'). Don't include
// the hyphen. This is optional, but one of either Short of Long must be
// specified.
Short rune
// Long option name, used for double-dashed args (like '--all'). Don't
// include the hyphens. This is optional, but one of either Short of Long
// must be specified.
Long string
// Set to true if this option is a flag, ie. it takes no value.
Flag bool
// If set, adds a simple from-a-list constraint to this option. The
// available choices will be appended to the option's headline. Has no
// effect on flags.
Choices []string
// Sets a term for this option's value - usually uppercase (like
// '-p/--person NAME'). Optional but recommended.
Metavar string
// Summary of the option. Displayed in the command help, and at the top of
// the command's help output. Text inside {curly braces} will be
// highlighted.
Headline string
}
Configuration for a single option, providing a value or a flag.
type OptionResult ¶
type OptionResult struct {
// The original Option that this OptionResult provides for.
Option *Option
// The option's string value. This may be blank if an empty value was
// supplied (eg. --opt ”) - check IsSet to be sure.
//
// If the option is a flag, this will always be blank.
Value string
// Whether the option was supplied.
IsSet bool
}
Parsing results for a single option.
type Result ¶
type Result struct {
// Suggested action. Note that regardless of this value, Errs may be
// populated.
Action Action
// All errors encountered so far. You may append your own during your own
// validations.
Errs []error
// The app you called Parse(...) on.
App *App
// The chosen command. May be nil if Action != Proceed.
Command *Command
// Map of option values.
//
// You can access values with either the short or long option names. Don't
// include hyphens - eg. use "o" or "opt" rather than "-o" or "--opt".
Options map[string]*OptionResult
// List of positional args.
//
// In the case of too many args being supplied, len(Args) won't be more than
// Command.Args.Count - that is, the extraneous args will be dropped. This
// obviously doesn't apply if Command.Args.Varadic is set.
Args []string
}
Parsing results. Returned by App.Parse(...).
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
args
command
|
|
|
options
command
|
|
|
readme
command
|
|
|
single-command
command
|
Click to show internal directories.
Click to hide internal directories.

