feat: enhanced error messages for cloud and oss specific commands (#347)
* feat: enhanced error messages for cloud and oss specific commands * chore: rename test
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
icontext "github.com/influxdata/influx-cli/v2/pkg/cli/context"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -18,3 +19,25 @@ func WithBeforeFns(fns ...cli.BeforeFunc) cli.BeforeFunc {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// AddMWToCmds is used to append a middleware to a list of existing commands.
|
||||
func AddMWToCmds(cmds []cli.Command, mw cli.BeforeFunc) []cli.Command {
|
||||
newCmds := make([]cli.Command, 0, len(cmds))
|
||||
|
||||
for _, cmd := range cmds {
|
||||
cmd.Before = WithBeforeFns(cmd.Before, mw)
|
||||
newCmds = append(newCmds, cmd)
|
||||
}
|
||||
|
||||
return newCmds
|
||||
}
|
||||
|
||||
var CloudOnly cli.BeforeFunc = func(ctx *cli.Context) error {
|
||||
icontext.SetCloudOnly(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
var OSSOnly cli.BeforeFunc = func(ctx *cli.Context) error {
|
||||
icontext.SetOssOnly(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user