utils

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BinaryName string

BinaryName the binary name to use in help docs

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 TopLevelCommand string

TopLevelCommand the top level command name

Functions

func BehaviorOnFatal added in v0.10.3

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

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

func CommaSeperated[T any](slice []T) (commaSep string)

func CreateTestDir

func CreateTestDir(additionalPath string) (string, string, error)

func DefaultBehaviorOnFatal added in v0.10.3

func DefaultBehaviorOnFatal()

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

func Exists

func Exists(path string) (bool, error)

Exists returns whether the given file or directory Exists

func ExistsInSlice

func ExistsInSlice(a string, b []string) bool

ExistsInSlice ranges over a slice returning true if the input exists in the slice

func Fatal added in v0.10.3

func Fatal(msg string, code int)

Fatal prints the message (if provided) and then exits. If V(2) or greater, glog.Logger().Fatal is invoked for extended information.

func NewPtr

func NewPtr[T any](obj T) *T

func SplitCommand added in v0.10.3

func SplitCommand(cmd *cobra.Command, _ interface{}) *cobra.Command

SplitCommand helper command to ignore the options object

func StandardErrorMessage added in v0.10.3

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 glog.

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

func TrimSpaceInSlice

func TrimSpaceInSlice(slice []string) []string

func UsageError added in v0.10.3

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

UsageError prints an error with how to run the help for the specified command.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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