flag

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: Apache-2.0 Imports: 2 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewValidationError

func NewValidationError(flag string, reason error) error

NewValidationError provides a convenient helper function to create flag validation errors usable by run.Config implementations.

Types

type Set added in v0.2.0

type Set struct {
	*pflag.FlagSet
	Name string
}

Set holds a pflag.FlagSet as well as an exported Name variable for allowing improved help usage information.

func NewSet added in v0.2.0

func NewSet(name string) *Set

NewSet returns a new FlagSet for usage in Config objects.

func (*Set) SensitiveStringVar added in v0.2.0

func (s *Set) SensitiveStringVar(p *string, name, value, usage string)

func (*Set) SensitiveStringVarP added in v0.2.0

func (s *Set) SensitiveStringVarP(p *string, name, shorthand, value, usage string)

type ValidationError

type ValidationError string

ValidationError provides the ability to create constant errors for run.Group validation errors, e.g. incorrect flag values.

const (
	// FlagErr can be used as formatting string for flag related validation
	// errors where the first variable lists the flag name and the second
	// variable is the actual error.
	FlagErr = "--%s error: %w"

	// ErrRequired is returned when required config options are not provided.
	ErrRequired ValidationError = "required"

	// ErrInvalidPath is returned when a path config option is invalid.
	ErrInvalidPath ValidationError = "invalid path"

	// ErrInvalidVal is returned when the value passed into a flag argument is invalid.
	ErrInvalidVal ValidationError = "invalid value"
)

func (ValidationError) Error

func (v ValidationError) Error() string

Error implements the built-in error interface.

Jump to

Keyboard shortcuts

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