From 7d68d6ede29bdcfd641118229b0607d9fe693047 Mon Sep 17 00:00:00 2001 From: gotjosh Date: Tue, 18 Jun 2019 10:25:37 +0100 Subject: [PATCH] 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. --- pkg/cmd/grafana-cli/commands/commands.go | 3 +-- pkg/cmd/grafana-cli/main.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/grafana-cli/commands/commands.go b/pkg/cmd/grafana-cli/commands/commands.go index 2ef9e78af4f..b5a47ecb765 100644 --- a/pkg/cmd/grafana-cli/commands/commands.go +++ b/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() diff --git a/pkg/cmd/grafana-cli/main.go b/pkg/cmd/grafana-cli/main.go index a83efb3fb76..016acde802a 100644 --- a/pkg/cmd/grafana-cli/main.go +++ b/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",