Sfoglia il codice sorgente

Allow setting config dir with env var

Signed-off-by: Christopher Crone <[email protected]>
Christopher Crone 5 anni fa
parent
commit
b7fb7e2e84
1 ha cambiato i file con 7 aggiunte e 3 eliminazioni
  1. 7 3
      cli/config/flags.go

+ 7 - 3
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)
 }