Documentation ¶
Overview ¶
Package optopia implements a fairly simple options style parser. It supports long (--option) and short (-o) options. The reason for its existence is that we wanted something simple, but with support for callback functions.
Index ¶
Constants ¶
View Source
const ( ErrNoSuchOption = err("no such option") ErrOptionRequiresValue = err("option requires value") ErrParsingValue = err("failure parsing option value") ErrDuplicateOption = err("duplicate option") ErrShortAndLongEmpty = err("long and short options both empty") )
These are standard error codes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option struct { // Long is the long form of the option (without the --). Long string // Short is the short (single character) form of the option. Short rune // HasArg indicates that the option takes a value. // This is presumed if ArgP is not nil. HasArg bool // ArgName is the name of the associated argument. // Used principally in help output. ArgName string // ArgP is used to store the value. At present // this can be a pointer to string, int, int64, uint64, or bool. // It can also be a TextUnmarshaller. ArgP interface{} // Handle is executed when this option is found, and passed the // raw string. If ArgP is set, then any conversion is // is done first. (If the conversion fails, then that error // is returned to the caller, and Handle is not called.) Handle func(string) error // Help is a short help message about the option. Help string // Seen is updated after Options.Parse. It is true if the option // was seen. This is useful for options that have no value. Seen bool // Raw contains the raw value for options that take one. // It is updated on Options.Parse. Raw string }
Option represents a single option. Allocate one of these and pass it to Options.Add() to register.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options are the main set of Options for a program. The zero value is usable immediately.
func (*Options) Help ¶ added in v0.2.0
Help returns a help string based on the options that have been registered. It only includes the option-specific help now -- nothing about the application itself is provided.
Click to show internal directories.
Click to hide internal directories.