Documentation
¶
Overview ¶
Package getopt provides a parser for command line options, supporting multi-value options such as -Wall,no-extra.
Index ¶
- type FlagGroup
- type Options
- func (o *Options) AddFlagGroup(shortName rune, longName, argsName, description string) *FlagGroup
- func (o *Options) AddFlagVar(shortName rune, longName string, pflag *bool, defval bool, description string)
- func (o *Options) AddStrList(shortName rune, longName string, plist *[]string, description string)
- func (o *Options) AddStrVar(shortName rune, longName string, pstr *string, defval string, ...)
- func (o *Options) Help(out io.Writer, generalUsage string)
- func (o *Options) Parse(args []string) (remainingArgs []string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func NewOptions ¶
func NewOptions() *Options
func (*Options) AddFlagGroup ¶
AddFlagGroup adds an option that takes multiple flag values.
Example:
var extra bool opts := NewOptions() warnings := opts.AddFlagGroup('W', "warnings", "warning,...", "Enable the given warnings") warnings.AddFlagVar("extra", &extra, false, "Print extra warnings")
func (*Options) AddFlagVar ¶
func (o *Options) AddFlagVar(shortName rune, longName string, pflag *bool, defval bool, description string)
AddFlagVar adds a boolean flag to the options.
Example:
var verbose bool opts := NewOptions() opts.AddFlagVar('v', "verbose", &verbose, false, "Enable verbose output")
This option can be used in the following ways:
-v --verbose --verbose=on (or yes, 1, true, enabled) --verbose=off (or no, 0, false, disabled)
func (*Options) AddStrList ¶
AddStrList adds a string option to the options that can be used multiple times.
Example:
var includes []string opts := NewOptions() opts.AddStrList('i', "include", &includes, nil, "Include the files matching the pattern")
This option can be used in the following ways:
-i "*.txt" -i "*.docx" --include "*.txt" --include "*.md" --include="*.txt" --include="*.md"
func (*Options) AddStrVar ¶
func (o *Options) AddStrVar(shortName rune, longName string, pstr *string, defval string, description string)
AddStrVar adds a string option to the options.
Example:
var outputFilename string opts := NewOptions() opts.AddStrVar('o', "output", &outputFilename, "", "Write the output to the given file")
This option can be used in the following ways:
-o output.txt --output output.txt --output=output.txt
Click to show internal directories.
Click to hide internal directories.