cmdutil

package
v0.0.0-...-0384855 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT, Apache-2.0 Imports: 9 Imported by: 6

Documentation

Index

Constants

View Source
const (
	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.

View Source
var FileExtensions = []string{".json", ".yaml", ".yml"}

Functions

func AddJsonFilenameFlag

func AddJsonFilenameFlag(flags *pflag.FlagSet, value *[]string, usage string)

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 `kubectl 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-Kubectl commands.

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

func GetFlagDuration

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

func GetFlagInt

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

Assumes the flag has a default value.

func GetFlagInt32

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

Assumes the flag has a default value.

func GetFlagInt64

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

Assumes the flag has a default value.

func GetFlagString

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

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 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-Kubectl commands.

func UsageErrorf

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

Types

type Aggregate

type Aggregate interface {
	error
	Errors() []error
	Is(error) bool
}

Aggregate represents an object that contains multiple errors, but does not necessarily have singular semantic meaning. The aggregate can be used with `errors.Is()` to check for the occurrence of a specific error type. Errors.As() is not supported, because the caller presumably cares about a specific error of potentially multiple that match the given type.

Jump to

Keyboard shortcuts

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