util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT 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 `onexctl 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-onexctl 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 RequireNoArguments

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

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

func SignToken

func SignToken(secretID string, secretKey string) (string, error)

SignToken is ued to sign a jwt token with some default options.

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-onexctl 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 {
	Login() (token string, err error)
	UserCenterClient() usercenterv1.UserCenterHTTPClient
	GatewayClient() gatewayv1.GatewayHTTPClient
	GetOptions() *clioptions.Options
}

func NewFactory

func NewFactory(opts *clioptions.Options) Factory

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