options

package
v0.0.0-...-b5aa0b6 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package options works in concert with flag, adding prettier printing of options.

Package options works in concert with flag, adding prettier printing of options.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Options is like flag.CommandLine, the current set of options. It is not kept
	// in lexicographical order. Initially, it will contain (at least) all the flags
	// from golang/glog.
	Options = []Option{}

	// String maps from name to value for string options added with Add.
	String = make(map[string]*string)

	// Bool maps from name to value for boolean options added with Add.
	Bool = make(map[string]*bool)

	// Int maps from name to value for int options added with Add.
	Int = make(map[string]*int)

	// Duration maps from name to value for time.Duration options added with
	// Add.
	Duration = make(map[string]*time.Duration)
)

Functions

func Add

func Add(option ...Option)

Add adds one or more options to Options, to the flag package's list, and to the approprate map (either String, Bool, Int, or Duration).

func Fail

func Fail(err error, msg string, args ...interface{})

Fail prints an error and accompanying message to os.Stderr, then exits the program with status 2. The err parameter can be nil.

func FailIf

func FailIf(err error, msg string, args ...interface{})

FailIf does the same thing as Fail, but only if err is not nil.

func Show

func Show(out io.Writer, category string)

Show pretty-prints all options. If a category is given, only those are shown.

func ShowAll

func ShowAll(out io.Writer)

Show pretty-prints all options.

func ShowRelevant

func ShowRelevant(out io.Writer, category ...Category)

ShowRelevant pretty-prints all options relevant to one or more categories.

func Usage

func Usage(msg string, args ...interface{})

Usage prints a message to os.Stderr, along with a note about the -help option, then exits the program with status 1.

func WarnIf

func WarnIf(err error, msg string, args ...interface{})

WarnIf prints an error and accompanying message, but only if err is not nil.

Types

type Category

type Category struct {

	// Name for this group of flags.
	Name string

	// Description for this group of flags.
	Description string
}

Category describes a group of related command-line flags.

type Option

type Option struct {
	// Name for this flag, e.g. "pass"
	Name string

	// Default value, e.g. "BogusPassword"
	Default interface{}

	// Placeholder description of the argument e.g. "<password>"
	Prototype string

	// Help message, e.g. "Password for decryption"
	Help string

	// Relevance is a comma-separated list of words, used to group the flags
	// into categories.
	Relevance string
}

Option is like flag.Flag, but supports prettier printing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL