Documentation ¶
Overview ¶
Package getopt provides simple command-line argument parsing, similar to the C function getopt described by POSIX. Optional arguments are not supported.
Index ¶
Constants ¶
const ( // The value EndOption is returned when a non-option argument // is encountered or there are no arguments left. EndOption = -1 )
Variables ¶
var ( // ErrOption is returned when an invalid option is encountered. ErrOption = errors.New("getopt: option not supported") // ErrNoArg is returned when a required option argument is missing. ErrNoArg = errors.New("getopt: no argument given") )
Functions ¶
This section is empty.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
A Parser holds the slice of strings containing the arguments given on the command line (the first one being the program's name), the index of the argument currently processed, the position of the next character to parse, the options string, a boolean telling whether the last option has an argument, a boolean telling whether all options have been parsed.
func NewParser ¶
NewParser returns a pointer to a Parser initialized with the given args and opts. The first item of args will be skipped by the parser. This allows the direct use of os.Args as args array. The opts string has the same format as the one used by the C function getopt described by POSIX. Optional arguments are not supported.
func (*Parser) Args ¶
Args returns a slice of strings containing the arguments that were not processed yet.
func (*Parser) OptArg ¶
OptArg returns the argument of the last option returned by Option, or the empty string if none was given.