flagutil

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

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

ValidTribools is an array of valid tribool string values

Functions

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 added in v0.37.0

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 RegisterGroupCompletionFunc added in v0.36.3

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

RegisterGroupCompletionFunc enables dynamic autocompletion for group flag

func RegisterServiceAccountCompletionFunc

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

RegisterServiceAccountCompletionFunc adds the service account list to flag dynamic completion

func RegisterTopicCompletionFunc added in v0.36.3

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

RegisterTopicCompletionFunc enables dynamic autocompletion for topic flag

func RegisterUserCompletionFunc

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

RegisterUserCompletionFunc adds the user list to flag dynamic completion

Types

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 added in v0.36.2

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 added in v0.37.0

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 added in v0.37.0

type Tribool string

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

func (*Tribool) Set added in v0.37.0

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

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

func (*Tribool) String added in v0.37.0

func (s *Tribool) String() string

String returns the tribool as a string

func (*Tribool) Type added in v0.37.0

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