util

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 12 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.

View Source
var Overwrite bool

Functions

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 DefaultSubCommandRun

func DefaultSubCommandRun() 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 Exists

func Exists(fileToCheck string) bool

func GenerateCode added in v0.1.7

func GenerateCode(filePath, codeTemplate, name string, o any) error

GenerateCode generate go source file.

func GetDirectoryFromPath

func GetDirectoryFromPath(filePath string) string

func GetFileNameWithoutExtension added in v1.2.0

func GetFileNameWithoutExtension(fileName string) string

func GetGoVersion

func GetGoVersion() string

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 PathExists

func PathExists(path string) (bool, error)

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 UsageErrorf

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

UsageErrorf returns error with command path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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