util

package
v0.0.0-...-3266887 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultErrorExitCode defines the default exit code.
	DefaultErrorExitCode = 1
)

Variables

View Source
var ErrExit = fmt.Errorf("exit")

ErrExit may be passed to CheckError to instruct it to output nothing but exit with status code 1.

Functions

func AddCleanFlags

func AddCleanFlags(cmd *cobra.Command)

AddCleanFlags add clean flags.

func BehaviorOnFatal

func BehaviorOnFatal(f func(string, int))

BehaviorOnFatal allows you to override the default behavior when a fatal error occurs, which is to call os.Exit(code). You can pass 'panic' as a function here if you prefer the panic() over os.Exit(1).

func CheckDiffErr

func CheckDiffErr(err error)

CheckDiffErr prints a user-friendly error to STDERR and exits with a non-zero and non-one exit code. Unrecognized errors will be printed with an "error: " prefix.

This method is meant specifically for `iamctl diff` and may be used by other commands.

func CheckErr

func CheckErr(err error)

CheckErr prints a user-friendly error to STDERR and exits with a non-zero exit code. Unrecognized errors will be printed with an "error: " prefix.

This method is generic to the command in use and may be used by non-IAM commands.

func CombineRequestErr

func CombineRequestErr(resp gorequest.Response, body string, errs []error) error

CombineRequestErr combines the http response error and error in errs array.

func DefaultBehaviorOnFatal

func DefaultBehaviorOnFatal()

DefaultBehaviorOnFatal allows you to undo any previous override. Useful in tests.

func DefaultSubCommandRun

func DefaultSubCommandRun(out io.Writer) func(c *cobra.Command, args []string)

DefaultSubCommandRun prints a command's help string to the specified output if no arguments (sub-commands) are provided, or a usage error otherwise.

func GetFlagBool

func GetFlagBool(cmd *cobra.Command, flag string) bool

GetFlagBool returns the value of the given flag.

func GetFlagDuration

func GetFlagDuration(cmd *cobra.Command, flag string) time.Duration

GetFlagDuration return the value of the given flag.

func GetFlagInt

func GetFlagInt(cmd *cobra.Command, flag string) int

GetFlagInt returns the value of the given flag.

func GetFlagInt32

func GetFlagInt32(cmd *cobra.Command, flag string) int32

GetFlagInt32 returns the value of the given flag.

func GetFlagInt64

func GetFlagInt64(cmd *cobra.Command, flag string) int64

GetFlagInt64 returns the value of the given flag.

func GetFlagString

func GetFlagString(cmd *cobra.Command, flag string) string

GetFlagString returns the value of the given flag.

func GetFlagStringArray

func GetFlagStringArray(cmd *cobra.Command, flag string) []string

GetFlagStringArray can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...).

func GetFlagStringSlice

func GetFlagStringSlice(cmd *cobra.Command, flag string) []string

GetFlagStringSlice can be used to accept multiple argument with flag repetition (e.g. -f arg1,arg2 -f arg3 ...).

func IsFilenameSliceEmpty

func IsFilenameSliceEmpty(filenames []string, directory string) bool

IsFilenameSliceEmpty checkes where filenames and directory are both zero value.

func IsSiblingCommandExists

func IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool

IsSiblingCommandExists receives a pointer to a cobra command and a target string. Returns true if the target string is found in the list of sibling commands.

func ManualStrip

func ManualStrip(file []byte) []byte

ManualStrip is used for dropping comments from a YAML file.

func MultilineError

func MultilineError(prefix string, err error) string

MultilineError returns a string representing an error that splits sub errors into their own lines. The returned string will end with a newline.

func MultipleErrors

func MultipleErrors(prefix string, errs []error) string

MultipleErrors returns a newline delimited string containing the prefix and referenced errors in standard form.

func NewForConfigOrDie

func NewForConfigOrDie() *marmotedu.Clientset

func RequireNoArguments

func RequireNoArguments(c *cobra.Command, args []string)

RequireNoArguments exits with a usage error if extra arguments are provided.

func StandardErrorMessage

func StandardErrorMessage(err error) (string, bool)

StandardErrorMessage translates common errors into a human readable message, or returns false if the error is not one of the recognized types. It may also log extended information to klog.

This method is generic to the command in use and may be used by non-IAM commands.

func TableWriterDefaultConfig

func TableWriterDefaultConfig(table *tablewriter.Table) *tablewriter.Table

func UsageErrorf

func UsageErrorf(cmd *cobra.Command, format string, args ...interface{}) error

UsageErrorf returns error with command path.

func Warning

func Warning(cmdErr io.Writer, newGeneratorName, oldGeneratorName string)

Warning write warning message to io.Writer.

Types

type Factory

type Factory interface {
	genericclioptions.RESTClientGetter

	// IAMClient gives you back an external iamclient
	IAMClient() (*iam.IamClient, error)

	// Returns a RESTClient for accessing IAM resources or an error.
	RESTClient() (*restclient.RESTClient, error)
}

Factory provides abstractions that allow the IAM command to be extended across multiple types of resources and different API sets. The rings are here for a reason. In order for composers to be able to provide alternative factory implementations they need to provide low level pieces of *certain* functions so that when the factory calls back into itself it uses the custom version of the function. Rather than try to enumerate everything that someone would want to override we split the factory into rings, where each ring can depend on methods in an earlier ring, but cannot depend upon peer methods in its own ring. TODO: make the functions interfaces TODO: pass the various interfaces on the factory directly into the command constructors (so the commands are decoupled from the factory).

func NewFactory

func NewFactory(clientGetter genericclioptions.RESTClientGetter) Factory

type MatchVersionFlags

type MatchVersionFlags struct {
	Delegate genericclioptions.RESTClientGetter

	RequireMatchedServerVersion bool
	// contains filtered or unexported fields
}

MatchVersionFlags is for setting the "match server version" function.

func NewMatchVersionFlags

func NewMatchVersionFlags(delegate genericclioptions.RESTClientGetter) *MatchVersionFlags

func (*MatchVersionFlags) AddFlags

func (f *MatchVersionFlags) AddFlags(flags *pflag.FlagSet)

func (*MatchVersionFlags) ToRESTConfig

func (f *MatchVersionFlags) ToRESTConfig() (*rest.Config, error)

ToRESTConfig implements RESTClientGetter. Returns a REST client configuration based on a provided path to a .iamconfig file, loading rules, and config flag overrides. Expects the AddFlags method to have been called.

func (*MatchVersionFlags) ToRawIAMConfigLoader

func (f *MatchVersionFlags) ToRawIAMConfigLoader() clientcmd.ClientConfig

type ValidateOptions

type ValidateOptions struct {
	EnableValidation bool
}

ValidateOptions defines the validate options.

Jump to

Keyboard shortcuts

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