Documentation ¶
Overview ¶
Package optparse parses command line arguments very similarly to GNU getopt_long(). It supports long options and optional arguments, but does not permute arguments. It is intended as a replacement for Go's flag package.
To use, define your options as an Option slice and pass it, along with the arguments string slice, to the Parse() function. It will return a slice of parsing results, which is to be iterated over just like getopt().
Index ¶
Constants ¶
const ( // KindNone means the option takes no argument KindNone Kind = iota // KindRequired means the argument requires an option KindRequired // KindOptional means the argument is optional KindOptional // ErrInvalid is used when an option is not recognized. ErrInvalid = "invalid option" // ErrMissing is used when a required argument is missing. ErrMissing = "option requires an argument" // ErrTooMany is used when an unwanted argument is provided. ErrTooMany = "option takes no arguments" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
Error represents all possible parsing errors. It embeds the option that has been misused, and Message is one of the three error strings. Implements error.
type Option ¶
Option represents a single argument. Unicode is fully supported, so a short option may be any character. Using the zero value for Long or Short means the option has form of that size. Kind must be one of the constants.
type Result ¶
Result is an individual successfully-parsed option. It embeds the original Option plus any argument. For options with optional arguments (KindOptional), it is not possible determine the difference between an empty supplied argument or no argument supplied.
func Parse ¶
Parse results a slice of the parsed results, the remaining arguments, and the first parser error. The results slice always contains results up until the first error.
The first argument, args[0], is skipped, and arguments are not permuted. Parsing stops at the first non-option argument, or "--". The latter is not included in the remaining, unparsed arguments.