Documentation ¶
Index ¶
- Constants
- Variables
- func AddJsonFilenameFlag(flags *pflag.FlagSet, value *[]string, usage string)
- func BehaviorOnFatal(f func(string, int))
- func CheckDiffErr(err error)
- func CheckErr(err error)
- func DefaultBehaviorOnFatal()
- func DefaultSubCommandRun(out io.Writer) func(c *cobra.Command, args []string)
- func GetFlagBool(cmd *cobra.Command, flag string) bool
- func GetFlagDuration(cmd *cobra.Command, flag string) time.Duration
- func GetFlagInt(cmd *cobra.Command, flag string) int
- func GetFlagInt32(cmd *cobra.Command, flag string) int32
- func GetFlagInt64(cmd *cobra.Command, flag string) int64
- func GetFlagString(cmd *cobra.Command, flag string) string
- func GetFlagStringArray(cmd *cobra.Command, flag string) []string
- func GetFlagStringSlice(cmd *cobra.Command, flag string) []string
- func RequireNoArguments(c *cobra.Command, args []string)
- func StandardErrorMessage(err error) (string, bool)
- func UsageErrorf(cmd *cobra.Command, format string, args ...interface{}) error
- type Aggregate
Constants ¶
const (
DefaultErrorExitCode = 1
)
Variables ¶
var ErrExit = fmt.Errorf("exit")
ErrExit may be passed to CheckError to instruct it to output nothing but exit with status code 1.
var FileExtensions = []string{".json", ".yaml", ".yml"}
Functions ¶
func AddJsonFilenameFlag ¶
func BehaviorOnFatal ¶
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 ¶
DefaultSubCommandRun prints a command's help string to the specified output if no arguments (sub-commands) are provided, or a usage error otherwise.
func GetFlagInt ¶
Assumes the flag has a default value.
func GetFlagInt32 ¶
Assumes the flag has a default value.
func GetFlagInt64 ¶
Assumes the flag has a default value.
func GetFlagStringArray ¶
GetFlagStringArray can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)
func GetFlagStringSlice ¶
GetFlagStringSlice can be used to accept multiple argument with flag repetition (e.g. -f arg1,arg2 -f arg3 ...)
func RequireNoArguments ¶
RequireNoArguments exits with a usage error if extra arguments are provided.
func StandardErrorMessage ¶
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.
Types ¶
type Aggregate ¶
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.