getopt

package
v21.1.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2021 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package getopt provides a parser for command line options, supporting multi-value options such as -Wall,no-extra.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FlagGroup

type FlagGroup struct {
	// contains filtered or unexported fields
}

func (*FlagGroup) AddFlagVar

func (fg *FlagGroup) AddFlagVar(name string, flag *bool, defval bool, description string)

type Options

type Options struct {
	// contains filtered or unexported fields
}

func NewOptions

func NewOptions() *Options

func (*Options) AddFlagGroup

func (o *Options) AddFlagGroup(shortName rune, longName, argsName, description string) *FlagGroup

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

func (o *Options) AddStrList(shortName rune, longName string, plist *[]string, description string)

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

func (*Options) Help

func (o *Options) Help(out io.Writer, generalUsage string)

Help writes a summary of the options to the given writer, in tabular format.

func (*Options) Parse

func (o *Options) Parse(args []string) (remainingArgs []string, err error)

Parse extracts the command line options from the given arguments. args[0] is the program name, as in os.Args.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳