flagutil

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package flagutil is a helper package for processing and interactive command line flags

Index

Constants

View Source
const (
	TRIBOOL_TRUE    = "true"
	TRIBOOL_FALSE   = "false"
	TRIBOOL_DEFAULT = ""
)

Variables

View Source
var (
	ValidOutputFormats = []string{dump.JSONFormat, dump.YAMLFormat, dump.YMLFormat}
)

ValidTribools is an array of valid tribool string values

Functions

func DebugEnabled

func DebugEnabled() bool

DebugEnabled returns a boolean flag that indicates if the verbose mode is enabled

func EnableOutputFlagCompletion

func EnableOutputFlagCompletion(cmd *cobra.Command)

EnableOutputFlagCompletion enables autocompletion for output flag

func EnableStaticFlagCompletion

func EnableStaticFlagCompletion(cmd *cobra.Command, flagName string, validValues []string)

EnableStaticFlagCompletion enables autocompletion for flags with predefined valid values

func FlagDescription

func FlagDescription(localizer localize.Localizer, messageID string, validOptions ...string) string

FlagDescription creates a flag description and adds a list of valid options (if any)

func IsTriboolValid

func IsTriboolValid(val string) error

IsTriboolValid validates if a string corresponds to a valid tribool value

func IsValidInput

func IsValidInput(input string, validValues ...string) bool

IsValidInput checks if the input value is in the range of valid values

func RegisterServiceAccountCompletionFunc

func RegisterServiceAccountCompletionFunc(cmd *cobra.Command, f *factory.Factory) error

RegisterServiceAccountCompletionFunc adds the service account list to flag dynamic completion

func RegisterUserCompletionFunc

func RegisterUserCompletionFunc(cmd *cobra.Command, flagName string, f *factory.Factory) error

RegisterUserCompletionFunc adds the user list to flag dynamic completion

func RequiredWhenNonInteractiveError

func RequiredWhenNonInteractiveError(flags ...string) error

func StringInSlice added in v0.41.2

func StringInSlice(a string, list []string) bool

StringInSlice checks if a string is in a slice. It is used when array of strings is passed as flag value or argument

func ValidateOutput

func ValidateOutput(v string) error

ValidateOutput checks if value v is a valid value for --output

func VerboseFlag

func VerboseFlag(flags *pflag.FlagSet)

VerboseFlag adds the verbose flag to the given set of command line flags.

Types

type Error

type Error struct {
	Err error
}

func InvalidValueError

func InvalidValueError(flag string, val interface{}, validOptions ...string) *Error

InvalidValueError returns an error when an invalid flag value is provided

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type FlagOptions

type FlagOptions struct {
	Required func() error
}

FlagOptions defines additional flag options

func WithFlagOptions

func WithFlagOptions(cmd *cobra.Command, flagName string) *FlagOptions

WithFlagOptions returns additional functions to custom the default flag settings

type FlagSet

type FlagSet struct {
	*pflag.FlagSet
	// contains filtered or unexported fields
}

func NewFlagSet

func NewFlagSet(cmd *cobra.Command, localizer localize.Localizer) *FlagSet

NewFlagSet returns a new flag set with some common flags

func (*FlagSet) AddBypassTermsCheck

func (fs *FlagSet) AddBypassTermsCheck(bypass *bool)

AddBypassTermsCheck adds a flag to allow bypassing of the terms check before creating an instance

func (*FlagSet) AddOutput

func (fs *FlagSet) AddOutput(output *string)

AddOutput adds an output flag to the command

func (*FlagSet) AddPage

func (fs *FlagSet) AddPage(page *int32)

AddPage adds a "page" flag to the command

func (*FlagSet) AddSize

func (fs *FlagSet) AddSize(page *int32)

AddSize adds a "size" flag to the command

func (*FlagSet) AddYes

func (fs *FlagSet) AddYes(yes *bool)

AddYes adds a "yes" flag to the command

func (*FlagSet) TriBoolVar

func (fs *FlagSet) TriBoolVar(p *Tribool, name string, value Tribool, usage string)

TriBoolVar defines a tribool flag with specified name, default value, and usage string. The argument p points to a tribool variable in which to store the value of the flag.

type Tribool

type Tribool string

Tribool is a tri-state boolean where extra state corresponds to ""

func (*Tribool) Set

func (s *Tribool) Set(val string) error

Set accepts the CLI input as string and assigns it to the tribool variable

func (*Tribool) String

func (s *Tribool) String() string

String returns the tribool as a string

func (*Tribool) Type

func (s *Tribool) Type() string

Type returns the type of flag

Jump to

Keyboard shortcuts

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