options

package
v1.0.82 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// OptionBatchMode command line option to enable batch mode
	OptionBatchMode = "batch-mode"

	// OptionVerbose command line option to enable verbose logging
	OptionVerbose = "verbose"
)
View Source
const (
	// DefaultErrorExitCode is the default exit code in case of an error
	DefaultErrorExitCode = 1

	// DefaultSuggestionsMinimumDistance default distance when generating suggestions if an option/arg is wrong
	DefaultSuggestionsMinimumDistance = 2
)

Variables

View Source
var (

	// ErrExit can be used to exit with a non 0 exit code without any error message
	ErrExit = fmt.Errorf("exit")
)

Functions

func CheckErr

func CheckErr(err error)

CheckErr prints a user friendly error to STDERR and exits with a non-zero exit code.

func InvalidArg

func InvalidArg(value string, values []string) error

func InvalidArgError

func InvalidArgError(value string, err error) error

func InvalidArgf

func InvalidArgf(value string, message string, a ...interface{}) error

func InvalidOption

func InvalidOption(name string, value string, values []string) error

func InvalidOptionf

func InvalidOptionf(option string, value interface{}, message string, a ...interface{}) error

InvalidOptionf returns an error that shows the invalid option.

func MissingOption

func MissingOption(name string) error

MissingOption reports a missing command line option using the full name expression.

func SuggestionsFor

func SuggestionsFor(typedName string, values []string, suggestionsMinimumDistance int, explicitSuggestions ...string) []string

Types

type BaseOptions added in v1.0.71

type BaseOptions struct {
	BatchMode bool
	Verbose   bool
	LogLevel  string
	Command   *cobra.Command
}

BaseOptions a few common options we tend to use in command line tools

func (*BaseOptions) AddBaseFlags added in v1.0.71

func (o *BaseOptions) AddBaseFlags(cmd *cobra.Command)

AddBaseFlags adds the base flags for all commands

func (*BaseOptions) Validate added in v1.0.71

func (o *BaseOptions) Validate() error

Validate verifies settings

Jump to

Keyboard shortcuts

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