From b7fb7e2e849a8a5a7a598b4cb761a122d435e140 Mon Sep 17 00:00:00 2001 From: Christopher Crone Date: Tue, 19 May 2020 14:05:51 +0200 Subject: [PATCH] Allow setting config dir with env var Signed-off-by: Christopher Crone --- cli/config/flags.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/config/flags.go b/cli/config/flags.go index de0c04f07..b9b3b3ffc 100644 --- a/cli/config/flags.go +++ b/cli/config/flags.go @@ -51,10 +51,14 @@ type ConfigFlags struct { // AddConfigFlags adds persistent (global) flags func (c *ConfigFlags) AddConfigFlags(flags *pflag.FlagSet) { - flags.StringVar(&c.Config, ConfigFlagName, filepath.Join(home(), ConfigFileDir), "Location of the client config files `DIRECTORY`") + flags.StringVar(&c.Config, ConfigFlagName, confDir(), "Location of the client config files `DIRECTORY`") } -func home() string { +func confDir() string { + env := os.Getenv("DOCKER_CONFIG") + if env != "" { + return env + } home, _ := os.UserHomeDir() - return home + return filepath.Join(home, ConfigFileDir) }