From 06425d5282286d317b5f1afb1e75e320653e19fc Mon Sep 17 00:00:00 2001 From: Deepesh Pathak Date: Tue, 3 Dec 2019 17:07:23 +0530 Subject: [PATCH 1/2] cmd: fix config file from env variable issue in subcommands * Fixes #4311 * Each subcommand can specify the config file to use using the environment varaible which is of the form `_CONFIG`, for example `DGRAPH_ZERO_CONFIG`. So with a `config.json` looking like this we can override the config variables. ```json { "my": "localhost:5180", "port_offset": 100, "idx": 1 } ``` Override the configuration using the above config file using the command ```bash DGRAPH_ALPHA_CONFIG=config.json dgraph alpha DGRAPH_ZERO_CONFIG=config.json dgraph zero ``` Signed-off-by: Deepesh Pathak --- dgraph/cmd/root.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dgraph/cmd/root.go b/dgraph/cmd/root.go index 6df198cd997..d3027afdb91 100644 --- a/dgraph/cmd/root.go +++ b/dgraph/cmd/root.go @@ -127,11 +127,14 @@ func initCmds() { x.CheckfNoTrace(os.Chdir(cwd)) } - cfg := rootConf.GetString("config") - if cfg == "" { - return - } for _, sc := range subcommands { + // Set config file is provided for each subcommand, this is done + // for individual subcommand because each subcommand has it's own config + // prefix, like `dgraph zero` expects the prefix to be `DGRAPH_ZERO` + cfg := sc.Conf.GetString("config") + if cfg == "" { + continue + } sc.Conf.SetConfigFile(cfg) x.Check(errors.Wrapf(sc.Conf.ReadInConfig(), "reading config")) setGlogFlags(sc.Conf) From f15752e85cfe3ddf859b630ed555cc2b25e09482 Mon Sep 17 00:00:00 2001 From: fristonio Date: Wed, 4 Dec 2019 17:56:55 +0530 Subject: [PATCH 2/2] cmd: fix grammar issue in docs Signed-off-by: fristonio --- dgraph/cmd/root.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dgraph/cmd/root.go b/dgraph/cmd/root.go index d3027afdb91..7c7ce70f6e5 100644 --- a/dgraph/cmd/root.go +++ b/dgraph/cmd/root.go @@ -129,8 +129,8 @@ func initCmds() { for _, sc := range subcommands { // Set config file is provided for each subcommand, this is done - // for individual subcommand because each subcommand has it's own config - // prefix, like `dgraph zero` expects the prefix to be `DGRAPH_ZERO` + // for individual subcommand because each subcommand has its own config + // prefix, like `dgraph zero` expects the prefix to be `DGRAPH_ZERO`. cfg := sc.Conf.GetString("config") if cfg == "" { continue