Documentation
¶
Index ¶
- Constants
- func VersionString() string
- type AliasFlag
- type Climate
- func (cl Climate) Abort(message string, err error, options ...interface{})
- func (cl *Climate) AddAlias(resolved_name, alias string)
- func (cl *Climate) AddFlag(flag clasp.Specification, flags ...AliasFlag)
- func (cl *Climate) AddFlagFunc(flag clasp.Specification, flagFn FlagFunc, flags ...AliasFlag)
- func (cl *Climate) AddOption(option clasp.Specification, flags ...AliasFlag)
- func (cl *Climate) AddOptionFunc(option clasp.Specification, optionFn OptionFunc, flags ...AliasFlag)
- func (cl Climate) Parse(argv []string, options ...interface{}) (result Result, err error)
- func (cl Climate) ParseAndVerify(argv []string, options ...interface{}) (result Result, err error)
- type FlagFunc
- type InitFlag
- type InitFunc
- type OptionFunc
- type ParseFlag
- type Result
Constants ¶
const ( VersionMajor uint16 = 0 VersionMinor uint16 = 8 VersionPatch uint16 = 1 VersionAB uint16 = 0xFFFF Version uint64 = (uint64(VersionMajor) << 48) + (uint64(VersionMinor) << 32) + (uint64(VersionPatch) << 16) + (uint64(VersionAB) << 0) )
const (
UsageHelpSuffix_Default = "; use --help for usage"
)
Variables ¶
This section is empty.
Functions ¶
func VersionString ¶ added in v0.6.1
func VersionString() string
Types ¶
type AliasFlag ¶
type AliasFlag int64
Type of flags passed to the Climate.AddFlag and Climate.AddOption methods.
type Climate ¶
type Climate struct {
Specifications []*clasp.Specification // The specifications created by [Init].
ParseFlags clasp.ParseFlag // Parsing flags.
Version interface{} // Version field that can be specified by application code in the function called by [Init].
VersionPrefix string // Version-prefix field that can be specified by application code in the function called by [Init].
InfoLines []string // Information lines field that can be specified by application code in the function called by [Init].
ValuesString string // Values-string field that can be specified by application code in the function called by [Init].
ProgramName string // Program-name field that can be specified by application code in the function called by [Init]. Defaults to `os.Args[0]`.
ValueNames []string // Specifies a list of value names that may be used in a contingent report when insufficient values are specified on the command-line (as determined by [Climate.ValuesConstraint]).
ValuesConstraint []int // An array of 1 or 2 numbers that specify the number of values, or the minimum and maximum number of values, required. A value of -1 means "no constraint", so, for example, the constraint `{2, -1}` means 2+ values are required.
UsageHelpSuffix string // An optional string to be applied to the end of the contingent report produced by [Climate.Abort]. Defaults to nothing. Specify ":" for default suffix string of "; use --help for usage". Insert leading "; " unless first character is punctuation.
// contains filtered or unexported fields
}
Structure representing a CLI parsing context, obtained from Init.
func Init ¶
Initialises a Climate instance, according to the given function (which may not be nil) and arguments.
func (Climate) Abort ¶ added in v0.3.0
Emits the given message and, optionally, err to the standard error stream, prefixed with the program name, and then terminates the process with a non-0 exit code.
func (*Climate) AddAlias ¶
Adds an alias to the Climate instance
The resolved_name param can be the name of a flag or option, or an option-with-value. The alias param is the alias (which must not contain an equals sign.
func (*Climate) AddFlag ¶
func (cl *Climate) AddFlag(flag clasp.Specification, flags ...AliasFlag)
Adds a (copy of the) flag to the Climate instance.
func (*Climate) AddFlagFunc ¶ added in v0.2.0
func (cl *Climate) AddFlagFunc(flag clasp.Specification, flagFn FlagFunc, flags ...AliasFlag)
Adds a (copy of the) flag to the Climate instance.
func (*Climate) AddOption ¶
func (cl *Climate) AddOption(option clasp.Specification, flags ...AliasFlag)
Adds a (copy of the) option to the Climate instance.
func (*Climate) AddOptionFunc ¶ added in v0.2.0
func (cl *Climate) AddOptionFunc(option clasp.Specification, optionFn OptionFunc, flags ...AliasFlag)
Adds a (copy of the) option to the Climate instance.
func (Climate) Parse ¶
Parses a command line, obtaining a Result instance representing the arguments received by the process.
func (Climate) ParseAndVerify ¶
Parses via Climate.Parse and verifies via Result.Verify.
Panics, rather than returns, if the ParseFlag_PanicOnFailure flag is specified
type FlagFunc ¶ added in v0.2.0
type FlagFunc func()
Type of callback function that may be specified to Climate.AddFlagFunc.
type InitFlag ¶
type InitFlag int64
Type of flags passed to the Init method.
const ( InitFlag_PanicOnFailure InitFlag = 1 << iota // Causes [Init] to panic if an error encountered during processing. InitFlag_NoHelpFlag // Suppresses the provision and processing of a help flag (aka "--help"). InitFlag_NoVersionFlag // Suppresses the provision and processing of a version flag (aka "--version"). )
const (
InitFlag_None InitFlag = 0 // No initialisation flags specified.
)
type OptionFunc ¶ added in v0.2.0
type OptionFunc func(option *clasp.Argument, specification *clasp.Specification)
Type of callback function that may be specified to Climate.AddOptionFunc, which receives the argument and its specification.
type ParseFlag ¶
type ParseFlag int64
Type of flags passed to the Climate.Parse and Climate.ParseAndVerify methods.
const (
ParseFlag_None ParseFlag = 0 // No parse flags specified.
)
type Result ¶
type Result struct {
Flags []*clasp.Argument // Array of all flags.
Options []*clasp.Argument // Array of all options.
Values []*clasp.Argument // Array of all values.
ProgramName string // The program name inferred by [Init], which may be overridden in the function called by [Init].
Argv []string // The original argument string array passed to [Parse].
// contains filtered or unexported fields
}
Structure representing CLI results, obtained from Climate.Parse.
func (Result) FlagIsSpecified ¶
Determines if the given flag is specified
func (Result) LookupFlag ¶ added in v0.2.0
Looks for a flag with the given id - name, or the specification instance - and returns it and the value true if found; if not, returns nil and false.
func (Result) LookupOption ¶
Looks for an option with the given id - name, or the specification instance - and returns it and the value true if found; if not, returns nil and false.