grafana-cli: Upgrade to urfave/cli v2 (#22402)

* grafana-cli: Upgrade to urfave/cli v2
This commit is contained in:
Arve Knudsen
2020-02-26 12:27:31 +01:00
committed by GitHub
parent 6bc369629d
commit eb98d9c15b
84 changed files with 10503 additions and 4755 deletions

View File

@ -5,11 +5,12 @@ import (
"os"
"runtime"
"github.com/codegangsta/cli"
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/urfave/cli/v2"
)
var version = "master"
@ -17,63 +18,67 @@ var version = "master"
func main() {
setupLogging()
app := cli.NewApp()
app.Name = "Grafana cli"
app.Usage = ""
app.Author = "Grafana Project"
app.Email = "https://github.com/grafana/grafana"
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "pluginsDir",
Usage: "path to the grafana plugin directory",
Value: utils.GetGrafanaPluginDir(runtime.GOOS),
EnvVar: "GF_PLUGIN_DIR",
app := &cli.App{
Name: "Grafana CLI",
Authors: []*cli.Author{
{
Name: "Grafana Project",
Email: "hello@grafana.com",
},
},
cli.StringFlag{
Name: "repo",
Usage: "url to the plugin repository",
Value: "https://grafana.com/api/plugins",
EnvVar: "GF_PLUGIN_REPO",
},
cli.StringFlag{
Name: "pluginUrl",
Usage: "Full url to the plugin zip file instead of downloading the plugin from grafana.com/api",
Value: "",
EnvVar: "GF_PLUGIN_URL",
},
cli.BoolFlag{
Name: "insecure",
Usage: "Skip TLS verification (insecure)",
},
cli.BoolFlag{
Name: "debug, d",
Usage: "enable debug logging",
},
cli.StringFlag{
Name: "configOverrides",
Usage: "configuration options to override defaults as a string. e.g. cfg:default.paths.log=/dev/null",
},
cli.StringFlag{
Name: "homepath",
Usage: "path to grafana install/home path, defaults to working directory",
},
cli.StringFlag{
Name: "config",
Usage: "path to config file",
Version: version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "pluginsDir",
Usage: "Path to the Grafana plugin directory",
Value: utils.GetGrafanaPluginDir(runtime.GOOS),
EnvVars: []string{"GF_PLUGIN_DIR"},
},
&cli.StringFlag{
Name: "repo",
Usage: "URL to the plugin repository",
Value: "https://grafana.com/api/plugins",
EnvVars: []string{"GF_PLUGIN_REPO"},
},
&cli.StringFlag{
Name: "pluginUrl",
Usage: "Full url to the plugin zip file instead of downloading the plugin from grafana.com/api",
Value: "",
EnvVars: []string{"GF_PLUGIN_URL"},
},
&cli.BoolFlag{
Name: "insecure",
Usage: "Skip TLS verification (insecure)",
},
&cli.BoolFlag{
Name: "debug, d",
Usage: "Enable debug logging",
},
&cli.StringFlag{
Name: "configOverrides",
Usage: "Configuration options to override defaults as a string. e.g. cfg:default.paths.log=/dev/null",
},
&cli.StringFlag{
Name: "homepath",
Usage: "Path to Grafana install/home path, defaults to working directory",
},
&cli.StringFlag{
Name: "config",
Usage: "Path to config file",
},
},
Commands: commands.Commands,
CommandNotFound: cmdNotFound,
}
app.Before = func(c *cli.Context) error {
services.Init(version, c.GlobalBool("insecure"))
services.Init(version, c.Bool("insecure"))
return nil
}
app.Commands = commands.Commands
app.CommandNotFound = cmdNotFound
if err := app.Run(os.Args); err != nil {
logger.Errorf("%v", err)
logger.Errorf("%s: %s %s\n", color.RedString("Error"), color.RedString("✗"), err)
os.Exit(1)
}
}