Documentation ¶
Overview ¶
Package cmdline provides command line option handling.
Index ¶
- Variables
- func Copyright() string
- func LongVersion() string
- func ShortVersion() string
- type Cmd
- type CmdLine
- func (cl *CmdLine) AddCommand(cmd Cmd)
- func (cl *CmdLine) DisplayUsage()
- func (cl *CmdLine) FatalError(err error)
- func (cl *CmdLine) FatalIfError(err error)
- func (cl *CmdLine) FatalMsg(msg string)
- func (cl *CmdLine) NewBoolArrayOption(val *[]bool) *Option
- func (cl *CmdLine) NewBoolOption(val *bool) *Option
- func (cl *CmdLine) NewDurationArrayOption(val *[]time.Duration) *Option
- func (cl *CmdLine) NewDurationOption(val *time.Duration) *Option
- func (cl *CmdLine) NewFloat32ArrayOption(val *[]float32) *Option
- func (cl *CmdLine) NewFloat32Option(val *float32) *Option
- func (cl *CmdLine) NewFloat64ArrayOption(val *[]float64) *Option
- func (cl *CmdLine) NewFloat64Option(val *float64) *Option
- func (cl *CmdLine) NewInt16ArrayOption(val *[]int16) *Option
- func (cl *CmdLine) NewInt16Option(val *int16) *Option
- func (cl *CmdLine) NewInt32ArrayOption(val *[]int32) *Option
- func (cl *CmdLine) NewInt32Option(val *int32) *Option
- func (cl *CmdLine) NewInt64ArrayOption(val *[]int64) *Option
- func (cl *CmdLine) NewInt64Option(val *int64) *Option
- func (cl *CmdLine) NewInt8ArrayOption(val *[]int8) *Option
- func (cl *CmdLine) NewInt8Option(val *int8) *Option
- func (cl *CmdLine) NewIntArrayOption(val *[]int) *Option
- func (cl *CmdLine) NewIntOption(val *int) *Option
- func (cl *CmdLine) NewOption(value Value) *Option
- func (cl *CmdLine) NewStringArrayOption(val *[]string) *Option
- func (cl *CmdLine) NewStringOption(val *string) *Option
- func (cl *CmdLine) NewUint16ArrayOption(val *[]uint16) *Option
- func (cl *CmdLine) NewUint16Option(val *uint16) *Option
- func (cl *CmdLine) NewUint32ArrayOption(val *[]uint32) *Option
- func (cl *CmdLine) NewUint32Option(val *uint32) *Option
- func (cl *CmdLine) NewUint64ArrayOption(val *[]uint64) *Option
- func (cl *CmdLine) NewUint64Option(val *uint64) *Option
- func (cl *CmdLine) NewUint8ArrayOption(val *[]uint8) *Option
- func (cl *CmdLine) NewUint8Option(val *uint8) *Option
- func (cl *CmdLine) NewUintArrayOption(val *[]uint) *Option
- func (cl *CmdLine) NewUintOption(val *uint) *Option
- func (cl *CmdLine) Parse(args []string) []string
- func (cl *CmdLine) RunCommand(args []string) error
- func (cl *CmdLine) SetWriter(w io.Writer)
- func (cl *CmdLine) Write(p []byte) (n int, err error)
- type Option
- type Options
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( // AppCmdName holds the application's name as specified on the command // line. AppCmdName string // AppName holds the name of the application. By default, this is the same // as AppCmdName. AppName string // CopyrightYears holds the years to place in the copyright banner. CopyrightYears string // CopyrightHolder holds the name of the copyright holder. CopyrightHolder string // License holds the license the software is being distributed under. This // is intended to be a simple one line description, such as "Mozilla // Public License 2.0" and not the full license itself. License string // AppVersion holds the application's version information. Typically set // by the build system. AppVersion string // GitVersion holds the git revision and clean/dirty status and should be // set by the build system. GitVersion string // BuildNumber holds the build number and should be set by the build // system. BuildNumber string // AppIdentifier holds the uniform type identifier (UTI) for the // application. This should contain only alphanumeric (A-Z,a-z,0-9), // hyphen (-), and period (.) characters. The string should also be in // reverse-DNS format. For example, if your company’s domain is Ajax.com // and you create an application named Hello, you could assign the string // com.Ajax.Hello as your AppIdentifier. AppIdentifier string )
Functions ¶
func LongVersion ¶ added in v1.22.0
func LongVersion() string
LongVersion returns a combination of the app version and the build number. If AppVersion has not been set, then "0.0" will be used instead.
func ShortVersion ¶ added in v1.22.0
func ShortVersion() string
ShortVersion returns the app version. If AppVersion has not been set, then "0.0" will be returned instead.
Types ¶
type Cmd ¶
type Cmd interface { // Name should return the name of the command as it needs to be entered on // the command line. Name() string // Usage should return a description of what the command does. Usage() string // Run will be called to run the command. It will be passed a fresh // command line created from the command line that was parsed to determine // this command would be run, along with the arguments that have not yet // been consumed. The first argument, much like an application called from // main, will be the name of the command. Run(cmdLine *CmdLine, args []string) error }
Cmd represents a sub-command available on the command-line.
type CmdLine ¶
type CmdLine struct { // UsageSuffix, if set, will be appended to the 'Usage: ' line of the // output. UsageSuffix string // Description, if set, will be inserted after the program identity // section, before the usage. Description string // contains filtered or unexported fields }
CmdLine holds information about the command line.
func New ¶
New creates a new CmdLine. If 'includeDefaultOptions' is true, help (-h, --help) and version (-v, --version, along with hidden -V, --Version for long variants) options will be added, otherwise, only the help options will be added, although they will be hidden.
func (*CmdLine) AddCommand ¶
AddCommand adds a command to the available commands.
func (*CmdLine) DisplayUsage ¶
func (cl *CmdLine) DisplayUsage()
DisplayUsage displays the program usage information.
func (*CmdLine) FatalError ¶
FatalError emits an error message and causes the program to exit.
func (*CmdLine) FatalIfError ¶
FatalIfError emits an error message and causes the program to exit if err != nil.
func (*CmdLine) NewBoolArrayOption ¶
NewBoolArrayOption creates a new []bool Option and attaches it to this CmdLine.
func (*CmdLine) NewBoolOption ¶
NewBoolOption creates a new bool Option and attaches it to this CmdLine.
func (*CmdLine) NewDurationArrayOption ¶
NewDurationArrayOption creates a new []time.Duration Option and attaches it to this CmdLine.
func (*CmdLine) NewDurationOption ¶
NewDurationOption creates a new time.Duration Option and attaches it to this CmdLine.
func (*CmdLine) NewFloat32ArrayOption ¶
NewFloat32ArrayOption creates a new []float32 Option and attaches it to this CmdLine.
func (*CmdLine) NewFloat32Option ¶
NewFloat32Option creates a new float32 Option and attaches it to this CmdLine.
func (*CmdLine) NewFloat64ArrayOption ¶
NewFloat64ArrayOption creates a new []float64 Option and attaches it to this CmdLine.
func (*CmdLine) NewFloat64Option ¶
NewFloat64Option creates a new float64 Option and attaches it to this CmdLine.
func (*CmdLine) NewInt16ArrayOption ¶
NewInt16ArrayOption creates a new []int16 Option and attaches it to this CmdLine.
func (*CmdLine) NewInt16Option ¶
NewInt16Option creates a new int16 Option and attaches it to this CmdLine.
func (*CmdLine) NewInt32ArrayOption ¶
NewInt32ArrayOption creates a new []int32 Option and attaches it to this CmdLine.
func (*CmdLine) NewInt32Option ¶
NewInt32Option creates a new int32 Option and attaches it to this CmdLine.
func (*CmdLine) NewInt64ArrayOption ¶
NewInt64ArrayOption creates a new []int64 Option and attaches it to this CmdLine.
func (*CmdLine) NewInt64Option ¶
NewInt64Option creates a new int64 Option and attaches it to this CmdLine.
func (*CmdLine) NewInt8ArrayOption ¶
NewInt8ArrayOption creates a new []int8 Option and attaches it to this CmdLine.
func (*CmdLine) NewInt8Option ¶
NewInt8Option creates a new int8 Option and attaches it to this CmdLine.
func (*CmdLine) NewIntArrayOption ¶
NewIntArrayOption creates a new []int Option and attaches it to this CmdLine.
func (*CmdLine) NewIntOption ¶
NewIntOption creates a new int Option and attaches it to this CmdLine.
func (*CmdLine) NewStringArrayOption ¶
NewStringArrayOption creates a new []string Option and attaches it to this CmdLine.
func (*CmdLine) NewStringOption ¶
NewStringOption creates a new string Option and attaches it to this CmdLine.
func (*CmdLine) NewUint16ArrayOption ¶
NewUint16ArrayOption creates a new []uint16 Option and attaches it to this CmdLine.
func (*CmdLine) NewUint16Option ¶
NewUint16Option creates a new uint16 Option and attaches it to this CmdLine.
func (*CmdLine) NewUint32ArrayOption ¶
NewUint32ArrayOption creates a new []uint32 Option and attaches it to this CmdLine.
func (*CmdLine) NewUint32Option ¶
NewUint32Option creates a new uint32 Option and attaches it to this CmdLine.
func (*CmdLine) NewUint64ArrayOption ¶
NewUint64ArrayOption creates a new []uint64 Option and attaches it to this CmdLine.
func (*CmdLine) NewUint64Option ¶
NewUint64Option creates a new uint64 Option and attaches it to this CmdLine.
func (*CmdLine) NewUint8ArrayOption ¶
NewUint8ArrayOption creates a new []uint8 Option and attaches it to this CmdLine.
func (*CmdLine) NewUint8Option ¶
NewUint8Option creates a new uint8 Option and attaches it to this CmdLine.
func (*CmdLine) NewUintArrayOption ¶
NewUintArrayOption creates a new []uint Option and attaches it to this CmdLine.
func (*CmdLine) NewUintOption ¶
NewUintOption creates a new uint Option and attaches it to this CmdLine.
func (*CmdLine) Parse ¶
Parse the 'args', filling in any options. Returns the remaining arguments that weren't used for option content.
func (*CmdLine) RunCommand ¶
RunCommand attempts to run a command. Pass in the command line arguments, usually the result from calling Parse().
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option represents an option available on the command line.
func (*Option) SetArg ¶
SetArg sets the argument name for this option. Returns self for easy chaining.
func (*Option) SetDefault ¶
SetDefault sets the default value for this option. Returns self for easy chaining.
Source Files ¶
- bool_value_gen.go
- cmd.go
- cmdline.go
- duration_value_gen.go
- float32_value_gen.go
- float64_value_gen.go
- help.go
- int16_value_gen.go
- int32_value_gen.go
- int64_value_gen.go
- int8_value_gen.go
- int_value_gen.go
- option.go
- options.go
- string_value_gen.go
- uint16_value_gen.go
- uint32_value_gen.go
- uint64_value_gen.go
- uint8_value_gen.go
- uint_value_gen.go
- usage.go
- version.go