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:
William Baker
2021-12-28 10:03:29 -05:00
committed by GitHub
parent 13d0827815
commit 7af0b2ae73
36 changed files with 1503 additions and 1985 deletions

View File

@ -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
}