Documentation ¶
Overview ¶
Package meta contains facilities to provide meta-information about programs and commands.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JoinCommands ¶
JoinCommands joins a list of commands into a single string.
Types ¶
type Flag ¶
type Flag struct { // The name of the underlying struct field this flag comes from. FieldName string // "Number" // Short and Long Names of the flag // each potentially more than one Short []string // ["n"] Long []string // ["number"] // Indicates if the flag is required Required bool // false // Name and Description of the flag in help texts Value string // "digit" Usage string // "A digit used within something" // Default value of the flag, as shown to the user. // When multiple default values are set, they are joined as a string. Default string // "42" // Valid choices for the option Choices []string }
Flag holds meta-information about a single flag of a command.
To create a new flag, see parser.NewFlag.
func (Flag) WriteLongSpecTo ¶
WriteLongSpecTo writes a long specification of f into w. It is of the form
-f, --flag value
WriteLongSpecTo does not add any brackets around the argument.
func (Flag) WriteMessageTo ¶
WriteMessageTo writes a long message of f to w. It is of the form
-f, --flag ARG
and
DESCRIPTION (choices CHOICE1, CHOICE2. default DEFAULT)
.
This function is implicity tested via other tests.
func (Flag) WriteSpecTo ¶
WriteSpecTo writes a short specification of f into w. It is of the form
--flag|-f value
WriteSpecTo adds braces around the argument if it is optional.
type Info ¶
type Info struct { BuildVersion string BuildTime time.Time Executable string // Name of the main executable of the program Description string // Description of the program }
Info holds information about a program
func (Info) FmtVersion ¶
FmtVersion formats version information about the current version It returns a string that should be presented to users.
type Meta ¶
type Meta struct { // Name of the Executable and Current command. // When Command is empty, the entire struct describes the program as a whole. Executable string Command string // Description holds a human-readable description of the object being described. Description string // Applicable Global, Command and Positional Flags. GlobalFlags []Flag CommandFlags []Flag Positionals []Positional // List of available sub-commands, only set when Command == "". Commands []string }
Meta holds meta-information about an entire program or a subcommand. It is used to generate a usage page.
func (Meta) WriteMessageTo ¶
WriteMessageTo writes the human-readable message of this meta into w
type Positional ¶
type Positional struct { // Name and Description of the positional in help texts Value string // defaults to "ARGUMENT" Usage string // Min and Max indicate how many positional arguments are expected for this command. // Min must be >= 0. Max must be either Min, or -1. // Max == -1 inidicates an unlimited number of repeats. Min, Max int }
Positional holds meta-information about a positional argument.
func (Positional) ValidRange ¶ added in v0.0.4
func (pos Positional) ValidRange() bool
ValidRange checks if posititional has valid min and max values.
func (Positional) Validate ¶
func (pos Positional) Validate(count int) error
Validate checks if the correct number of positional arguments have been passed.
func (Positional) WriteSpecTo ¶
func (pos Positional) WriteSpecTo(w io.Writer)
WriteSpecTo writes a specification of this argument into w. A specification looks like "arg [arg...]".