Files
grafana/pkg/cmd/grafana-cli/commands/commandstest/context.go
Arve Knudsen eb98d9c15b grafana-cli: Upgrade to urfave/cli v2 (#22402)
* grafana-cli: Upgrade to urfave/cli v2
2020-02-26 12:27:31 +01:00

26 lines
589 B
Go

package commandstest
import (
"flag"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/urfave/cli/v2"
)
// NewCliContext creates a new CLI context with a certain set of flags.
func NewCliContext(flags map[string]string) (*utils.ContextCommandLine, error) {
app := cli.App{
Name: "Test",
}
flagSet := flag.NewFlagSet("Test", 0)
for flag, value := range flags {
flagSet.String(flag, "", "")
if err := flagSet.Set(flag, value); err != nil {
return nil, err
}
}
return &utils.ContextCommandLine{
Context: cli.NewContext(&app, flagSet, nil),
}, nil
}