mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 19:00:54 -06:00
cli: grafana-cli should receive flags from the command line (#17606)
grafana-cli should allow configuration overrides to be received from the command line. e.g. ``` grafana-cli admin reset-password cfg:default.paths.logs=custom/log/directory/ ``` Seems like we missed the inclusion of `flag.Parse` as we run the command, to be able to consume them. Additionally, it'll be useful for the user to know whenever these are being overriden or not - hence the addition of logging the configuration to be used as we run the command.
This commit is contained in:
parent
aa1f9cdd40
commit
6fbca90269
@ -19,12 +19,15 @@ func runDbCommand(command func(commandLine utils.CommandLine, sqlStore *sqlstore
|
|||||||
cmd := &utils.ContextCommandLine{Context: context}
|
cmd := &utils.ContextCommandLine{Context: context}
|
||||||
|
|
||||||
cfg := setting.NewCfg()
|
cfg := setting.NewCfg()
|
||||||
|
|
||||||
cfg.Load(&setting.CommandLineArgs{
|
cfg.Load(&setting.CommandLineArgs{
|
||||||
Config: cmd.String("config"),
|
Config: cmd.String("config"),
|
||||||
HomePath: cmd.String("homepath"),
|
HomePath: cmd.String("homepath"),
|
||||||
Args: flag.Args(),
|
Args: flag.Args(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
cfg.LogConfigSources()
|
||||||
|
|
||||||
engine := &sqlstore.SqlStore{}
|
engine := &sqlstore.SqlStore{}
|
||||||
engine.Cfg = cfg
|
engine.Cfg = cfg
|
||||||
engine.Bus = bus.GetBus()
|
engine.Bus = bus.GetBus()
|
||||||
@ -93,21 +96,23 @@ var pluginCommands = []cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dbCommandFlags = []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "homepath",
|
||||||
|
Usage: "path to grafana install/home path, defaults to working directory",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "config",
|
||||||
|
Usage: "path to config file",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var adminCommands = []cli.Command{
|
var adminCommands = []cli.Command{
|
||||||
{
|
{
|
||||||
Name: "reset-admin-password",
|
Name: "reset-admin-password",
|
||||||
Usage: "reset-admin-password <new password>",
|
Usage: "reset-admin-password <new password>",
|
||||||
Action: runDbCommand(resetPasswordCommand),
|
Action: runDbCommand(resetPasswordCommand),
|
||||||
Flags: []cli.Flag{
|
Flags: dbCommandFlags,
|
||||||
cli.StringFlag{
|
|
||||||
Name: "homepath",
|
|
||||||
Usage: "path to grafana install/home path, defaults to working directory",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "config",
|
|
||||||
Usage: "path to config file",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "data-migration",
|
Name: "data-migration",
|
||||||
@ -117,6 +122,7 @@ var adminCommands = []cli.Command{
|
|||||||
Name: "encrypt-datasource-passwords",
|
Name: "encrypt-datasource-passwords",
|
||||||
Usage: "Migrates passwords from unsecured fields to secure_json_data field. Return ok unless there is an error. Safe to execute multiple times.",
|
Usage: "Migrates passwords from unsecured fields to secure_json_data field. Return ok unless there is an error. Safe to execute multiple times.",
|
||||||
Action: runDbCommand(datamigrations.EncryptDatasourcePaswords),
|
Action: runDbCommand(datamigrations.EncryptDatasourcePaswords),
|
||||||
|
Flags: dbCommandFlags,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -17,6 +18,7 @@ var version = "master"
|
|||||||
func main() {
|
func main() {
|
||||||
setupLogging()
|
setupLogging()
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "Grafana cli"
|
app.Name = "Grafana cli"
|
||||||
app.Usage = ""
|
app.Usage = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user