flagutil

package
v0.0.0-...-2dac0ec Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Overview

Package flagutil contains flag utilities like implementations of flag.Value and flag.Getter interfaces. Also contains methods like ValidateFlags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequiredStringFlag

func RequiredStringFlag(name string, usage string, fs *flag.FlagSet) *string

RequiredStringFlag adds a required string flag with the specified name. Note that ValidateFlags must be called to ensure that it is set. Returns a pointer to the string value set. Example usage: var reqstr = flagutil.RequiredStringFlag(name, usage, nil)

func main() {
	flag.Parse()
	if err := flagutil.ValidateFlags(nil); err != nil {
		log.Fatal(err)
	}
	log.Println(*reqstr)
}

Types

type FlagError

type FlagError struct {
	Flag *flag.Flag
	Err  error
}

FlagError is the error returned while validating a single flag.

func (*FlagError) Error

func (f *FlagError) Error() string

type MultiFlagError

type MultiFlagError []*FlagError

MultiFlagError is a slice of errors returned while validating flags.

func ValidateFlags

func ValidateFlags(fs *flag.FlagSet) MultiFlagError

ValidateFlags validates flags and logs a fatal message with all errors if found. Must be called after flag.Parse(). This is done by calling Get() on all flag values which implement the flag.Getter interface and collecting errors if returned.

func (MultiFlagError) Error

func (m MultiFlagError) Error() string

Jump to

Keyboard shortcuts

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