Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OptArg ¶
OptArg represents a single parsed option (and its argument, if applicable), as parsed by GetOpt.
func GetOpt ¶
func GetOpt( args []string, shortopts string, longopts []string, ) ( leftovers []string, optargs []OptArg, err error, )
GetOpt parses the provided args, according to shortopts and longopts; and returns the leftover args, parsed options with their arguments, and (if there was one) any encountered parsing error.
See the package documentation for a description of the shortops and longopts formats, as well as how the args are interpreted in their context.
If there is a programming error in shortopts or longopts (rather than a parsing error resulting from unexpected arguments in the resulting program), GetOpt may cause a runtime panic.
func GetOptSafe ¶
func GetOptSafe( args []string, shortopts string, longopts []string, ) ( leftovers []string, optargs []OptArg, err error, )
GetOptSafe works identically to GetOpt, but will not trigger runtime panics on errors such as programmer mistakes in shortopts or longopts. This is for situations, where you'd like to implement getopt(1), or otherwise allow the end user to specify their own shortops/longopts, and get a useful error message rather than a stack trace.
type ParseError ¶
type ParseError struct { // message and opt are used to build the friendly user-facing // error message. Message string Opt string // This can be somewhat useful in debugging. Unexpected string Expected string // contains filtered or unexported fields }
ParseError contains hints about what exactly went wrong when parsing the arguments in GetOpt. The resulting message (ParseError.Error()) should be displayed to the user.
func (ParseError) Error ¶
func (err ParseError) Error() string
Directories ¶
Path | Synopsis |
---|---|
This tiny example program serves as a little stress-test, attempting to parse (only parse!) all arguments supported by GNU coreutils ls(1).
|
This tiny example program serves as a little stress-test, attempting to parse (only parse!) all arguments supported by GNU coreutils ls(1). |