middleware

package
v2.7.5 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OSSBuildHeader   = "OSS"
	CloudBuildHeader = "Cloud"
)

Variables

View Source
var CloudOnly cli.BeforeFunc = func(ctx *cli.Context) error {
	icontext.SetCloudOnly(ctx)
	return nil
}
View Source
var HandleExit cli.ExitErrHandlerFunc = func(ctx *cli.Context, err error) {
	if err == nil {
		return
	}

	var header string
	var genericErr api.GenericOpenAPIError
	if errors.As(err, &genericErr) {
		header = genericErr.BuildHeader()
	}

	// Replace the error message with the relevant information if a platform-specific command was used on the wrong host.
	// Otherwise, pass the error message along as-is to the CLI exit handler.
	var setErr bool
	if header == OSSBuildHeader {
		if icontext.GetCloudOnly(ctx) {
			err = cli.NewExitError(WrongHostErrString(CloudBuildHeader, OSSBuildHeader), 1)
			setErr = true
		}
	} else if header == CloudBuildHeader {
		if icontext.GetOssOnly(ctx) {
			err = cli.NewExitError(WrongHostErrString(OSSBuildHeader, CloudBuildHeader), 1)
			setErr = true
		}
	}
	if !setErr {
		err = cli.NewExitError(fmt.Sprintf("Error: %v", err.Error()), 1)
	}

	cli.HandleExitCoder(err)
}
View Source
var NoArgs cli.BeforeFunc = func(ctx *cli.Context) error {

	if ctx.NArg() > 0 && ctx.App.Command(ctx.Args()[0]) == nil {
		cmdName := ctx.Command.Name
		if cmdName == "" && ctx.App.Name != "" {
			cmdName = ctx.App.Name
		}

		return fmt.Errorf("unknown command %q for %q", ctx.Args()[0], cmdName)
	}
	return nil
}
View Source
var OSSOnly cli.BeforeFunc = func(ctx *cli.Context) error {
	icontext.SetOssOnly(ctx)
	return nil
}

Functions

func AddMWToCmds added in v2.3.0

func AddMWToCmds(cmds []cli.Command, mw cli.BeforeFunc) []cli.Command

AddMWToCmds is used to append a middleware to a list of existing commands.

func WithBeforeFns

func WithBeforeFns(fns ...cli.BeforeFunc) cli.BeforeFunc

WithBeforeFns returns a cli.BeforeFunc that calls each of the provided functions in order. NOTE: The first function to return an error will end execution and be returned as the error value of the composed function.

func WrongHostErrString added in v2.3.0

func WrongHostErrString(commandHost, actualHost string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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