diff --git a/dgraph/cmd/root.go b/dgraph/cmd/root.go index 6df198cd997..7c7ce70f6e5 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 its 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)