Browse Source

grafana-cli: Fix receiving flags via command line (#17617)

`grafana-cli` uses the third-party library to define the flags and not
the standard library. Using `flag.Parse` conflicts with the defined
flags from our third-party library.

In the case where `flag.Parse` is used, the CLI assumes that definitions
provided are not needed and will not define them; producing errors of
the kind `flag provided but not defined --example-flag`.

Using the context to read any arguments (including flags) is the
recommended approach by the third-party library.
gotjosh 6 years ago
parent
commit
7d68d6ede2
2 changed files with 2 additions and 4 deletions
  1. 1 2
      pkg/cmd/grafana-cli/commands/commands.go
  2. 1 2
      pkg/cmd/grafana-cli/main.go

+ 1 - 2
pkg/cmd/grafana-cli/commands/commands.go

@@ -1,7 +1,6 @@
 package commands
 
 import (
-	"flag"
 	"os"
 
 	"github.com/codegangsta/cli"
@@ -23,7 +22,7 @@ func runDbCommand(command func(commandLine utils.CommandLine, sqlStore *sqlstore
 		cfg.Load(&setting.CommandLineArgs{
 			Config:   cmd.String("config"),
 			HomePath: cmd.String("homepath"),
-			Args:     flag.Args(),
+			Args:     context.Args(),
 		})
 
 		cfg.LogConfigSources()

+ 1 - 2
pkg/cmd/grafana-cli/main.go

@@ -1,7 +1,6 @@
 package main
 
 import (
-	"flag"
 	"fmt"
 	"os"
 	"runtime"
@@ -18,13 +17,13 @@ var version = "master"
 func main() {
 	setupLogging()
 
-	flag.Parse()
 	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",