cmdline

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2018 License: MPL-2.0 Imports: 15 Imported by: 44

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 Copyright() string

Copyright returns the copyright notice.

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

func New(includeDefaultOptions bool) *CmdLine

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

func (cl *CmdLine) AddCommand(cmd Cmd)

AddCommand adds a command to the available commands.

func (*CmdLine) DisplayUsage

func (cl *CmdLine) DisplayUsage()

DisplayUsage displays the program usage information.

func (*CmdLine) FatalError

func (cl *CmdLine) FatalError(err error)

FatalError emits an error message and causes the program to exit.

func (*CmdLine) FatalIfError

func (cl *CmdLine) FatalIfError(err error)

FatalIfError emits an error message and causes the program to exit if err != nil.

func (*CmdLine) FatalMsg

func (cl *CmdLine) FatalMsg(msg string)

FatalMsg emits an error message and causes the program to exit.

func (*CmdLine) NewBoolArrayOption

func (cl *CmdLine) NewBoolArrayOption(val *[]bool) *Option

NewBoolArrayOption creates a new []bool Option and attaches it to this CmdLine.

func (*CmdLine) NewBoolOption

func (cl *CmdLine) NewBoolOption(val *bool) *Option

NewBoolOption creates a new bool Option and attaches it to this CmdLine.

func (*CmdLine) NewDurationArrayOption

func (cl *CmdLine) NewDurationArrayOption(val *[]time.Duration) *Option

NewDurationArrayOption creates a new []time.Duration Option and attaches it to this CmdLine.

func (*CmdLine) NewDurationOption

func (cl *CmdLine) NewDurationOption(val *time.Duration) *Option

NewDurationOption creates a new time.Duration Option and attaches it to this CmdLine.

func (*CmdLine) NewFloat32ArrayOption

func (cl *CmdLine) NewFloat32ArrayOption(val *[]float32) *Option

NewFloat32ArrayOption creates a new []float32 Option and attaches it to this CmdLine.

func (*CmdLine) NewFloat32Option

func (cl *CmdLine) NewFloat32Option(val *float32) *Option

NewFloat32Option creates a new float32 Option and attaches it to this CmdLine.

func (*CmdLine) NewFloat64ArrayOption

func (cl *CmdLine) NewFloat64ArrayOption(val *[]float64) *Option

NewFloat64ArrayOption creates a new []float64 Option and attaches it to this CmdLine.

func (*CmdLine) NewFloat64Option

func (cl *CmdLine) NewFloat64Option(val *float64) *Option

NewFloat64Option creates a new float64 Option and attaches it to this CmdLine.

func (*CmdLine) NewInt16ArrayOption

func (cl *CmdLine) NewInt16ArrayOption(val *[]int16) *Option

NewInt16ArrayOption creates a new []int16 Option and attaches it to this CmdLine.

func (*CmdLine) NewInt16Option

func (cl *CmdLine) NewInt16Option(val *int16) *Option

NewInt16Option creates a new int16 Option and attaches it to this CmdLine.

func (*CmdLine) NewInt32ArrayOption

func (cl *CmdLine) NewInt32ArrayOption(val *[]int32) *Option

NewInt32ArrayOption creates a new []int32 Option and attaches it to this CmdLine.

func (*CmdLine) NewInt32Option

func (cl *CmdLine) NewInt32Option(val *int32) *Option

NewInt32Option creates a new int32 Option and attaches it to this CmdLine.

func (*CmdLine) NewInt64ArrayOption

func (cl *CmdLine) NewInt64ArrayOption(val *[]int64) *Option

NewInt64ArrayOption creates a new []int64 Option and attaches it to this CmdLine.

func (*CmdLine) NewInt64Option

func (cl *CmdLine) NewInt64Option(val *int64) *Option

NewInt64Option creates a new int64 Option and attaches it to this CmdLine.

func (*CmdLine) NewInt8ArrayOption

func (cl *CmdLine) NewInt8ArrayOption(val *[]int8) *Option

NewInt8ArrayOption creates a new []int8 Option and attaches it to this CmdLine.

func (*CmdLine) NewInt8Option

func (cl *CmdLine) NewInt8Option(val *int8) *Option

NewInt8Option creates a new int8 Option and attaches it to this CmdLine.

func (*CmdLine) NewIntArrayOption

func (cl *CmdLine) NewIntArrayOption(val *[]int) *Option

NewIntArrayOption creates a new []int Option and attaches it to this CmdLine.

func (*CmdLine) NewIntOption

func (cl *CmdLine) NewIntOption(val *int) *Option

NewIntOption creates a new int Option and attaches it to this CmdLine.

func (*CmdLine) NewOption

func (cl *CmdLine) NewOption(value Value) *Option

NewOption creates a new Option and attaches it to this CmdLine.

func (*CmdLine) NewStringArrayOption

func (cl *CmdLine) NewStringArrayOption(val *[]string) *Option

NewStringArrayOption creates a new []string Option and attaches it to this CmdLine.

func (*CmdLine) NewStringOption

func (cl *CmdLine) NewStringOption(val *string) *Option

NewStringOption creates a new string Option and attaches it to this CmdLine.

func (*CmdLine) NewUint16ArrayOption

func (cl *CmdLine) NewUint16ArrayOption(val *[]uint16) *Option

NewUint16ArrayOption creates a new []uint16 Option and attaches it to this CmdLine.

func (*CmdLine) NewUint16Option

func (cl *CmdLine) NewUint16Option(val *uint16) *Option

NewUint16Option creates a new uint16 Option and attaches it to this CmdLine.

func (*CmdLine) NewUint32ArrayOption

func (cl *CmdLine) NewUint32ArrayOption(val *[]uint32) *Option

NewUint32ArrayOption creates a new []uint32 Option and attaches it to this CmdLine.

func (*CmdLine) NewUint32Option

func (cl *CmdLine) NewUint32Option(val *uint32) *Option

NewUint32Option creates a new uint32 Option and attaches it to this CmdLine.

func (*CmdLine) NewUint64ArrayOption

func (cl *CmdLine) NewUint64ArrayOption(val *[]uint64) *Option

NewUint64ArrayOption creates a new []uint64 Option and attaches it to this CmdLine.

func (*CmdLine) NewUint64Option

func (cl *CmdLine) NewUint64Option(val *uint64) *Option

NewUint64Option creates a new uint64 Option and attaches it to this CmdLine.

func (*CmdLine) NewUint8ArrayOption

func (cl *CmdLine) NewUint8ArrayOption(val *[]uint8) *Option

NewUint8ArrayOption creates a new []uint8 Option and attaches it to this CmdLine.

func (*CmdLine) NewUint8Option

func (cl *CmdLine) NewUint8Option(val *uint8) *Option

NewUint8Option creates a new uint8 Option and attaches it to this CmdLine.

func (*CmdLine) NewUintArrayOption

func (cl *CmdLine) NewUintArrayOption(val *[]uint) *Option

NewUintArrayOption creates a new []uint Option and attaches it to this CmdLine.

func (*CmdLine) NewUintOption

func (cl *CmdLine) NewUintOption(val *uint) *Option

NewUintOption creates a new uint Option and attaches it to this CmdLine.

func (*CmdLine) Parse

func (cl *CmdLine) Parse(args []string) []string

Parse the 'args', filling in any options. Returns the remaining arguments that weren't used for option content.

func (*CmdLine) RunCommand

func (cl *CmdLine) RunCommand(args []string) error

RunCommand attempts to run a command. Pass in the command line arguments, usually the result from calling Parse().

func (*CmdLine) SetWriter

func (cl *CmdLine) SetWriter(w io.Writer)

SetWriter sets the io.Writer to use for output. By default, a new CmdLine uses os.Stderr.

func (*CmdLine) Write

func (cl *CmdLine) Write(p []byte) (n int, err error)

Write implements the io.Writer interface.

type Option

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

Option represents an option available on the command line.

func (*Option) SetArg

func (op *Option) SetArg(name string) *Option

SetArg sets the argument name for this option. Returns self for easy chaining.

func (*Option) SetDefault

func (op *Option) SetDefault(def string) *Option

SetDefault sets the default value for this option. Returns self for easy chaining.

func (*Option) SetName

func (op *Option) SetName(name string) *Option

SetName sets the name for this option. Returns self for easy chaining.

func (*Option) SetSingle

func (op *Option) SetSingle(ch rune) *Option

SetSingle sets the single character name for this option. Returns self for easy chaining.

func (*Option) SetUsage

func (op *Option) SetUsage(usage string) *Option

SetUsage sets the usage message for this option. Returns self for easy chaining.

type Options

type Options []*Option

Options represents a set of options.

func (Options) Len

func (op Options) Len() int

Len implements the sort.Interface interface.

func (Options) Less

func (op Options) Less(i, j int) bool

Less implements the sort.Interface interface.

func (Options) Swap

func (op Options) Swap(i, j int)

Swap implements the sort.Interface interface.

type Value

type Value interface {
	// Set the contents of this value.
	Set(value string) error
	// String implements the fmt.Stringer interface.
	String() string
}

Value represents a value that can be set for an Option.

type Version

type Version uint64

Version holds an encoded version number that contains fields for the major, minor, and patch release numbers as well as a build date and time.

func NewVersion

func NewVersion(major, minor, patch int, when time.Time) Version

NewVersion constructs a new version. If 'major', 'minor', or 'patch' are out of the permitted ranges, a value of 0 will be returned.

func NewVersionFromString

func NewVersionFromString(version string) Version

NewVersionFromString constructs a new version from a string.

func (Version) Day

func (v Version) Day() int

Day returns the build day associated with this version.

func (Version) Format

func (v Version) Format(includeVersionWord, includeBuildDateTime bool) string

Format the version. If 'includeVersionWord' is true, then the word "Version" will be included as needed. If 'includeBuildDateTime' is true, then the build date and time will be included.

func (Version) Hour

func (v Version) Hour() int

Hour returns the build hour associated with this version.

func (Version) IsDevelopment

func (v Version) IsDevelopment() bool

IsDevelopment returns true if this version has not been initialized.

func (Version) IsWhenUnset

func (v Version) IsWhenUnset() bool

IsWhenUnset returns true if the build time has not been initialized.

func (Version) Major

func (v Version) Major() int

Major returns the major release number associated with this version.

func (Version) Minor

func (v Version) Minor() int

Minor returns the minor release number associated with this version.

func (Version) Minute

func (v Version) Minute() int

Minute returns the build minute associated with this version.

func (Version) Month

func (v Version) Month() int

Month returns the build month associated with this version.

func (Version) Patch

func (v Version) Patch() int

Patch returns the patch release number associated with this version.

func (Version) Second

func (v Version) Second() int

Second returns the build second associated with this version.

func (Version) String

func (v Version) String() string

String implements the fmt.Stringer interface.

func (Version) When

func (v Version) When() time.Time

When returns the build date and time in UTC associated with this version.

func (Version) Year

func (v Version) Year() int

Year returns the build year associated with this version.

Directories

Path Synopsis
cmd
genvalues
genvalues creates the values.go content for the args package.
genvalues creates the values.go content for the args package.
genversion
genversion provides a simple way to generate a version with build date and time of 'now'.
genversion provides a simple way to generate a version with build date and time of 'now'.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL