feat: respect --quiet in config.go

When setting environment variables, we should respect a passed `--quiet` flag - and the respective environment variable. This will allow users to have a nicer experience when using the config functions within their own plugins.
This commit is contained in:
Jose Diaz-Gonzalez
2019-03-12 21:07:58 -04:00
parent c701429a05
commit c6a1c0dcbf

View File

@@ -2,6 +2,7 @@ package config
import ( import (
"fmt" "fmt"
"os"
"regexp" "regexp"
"github.com/dokku/dokku/plugins/common" "github.com/dokku/dokku/plugins/common"
@@ -46,8 +47,10 @@ func SetMany(appName string, entries map[string]string, restart bool) (err error
keys = append(keys, k) keys = append(keys, k)
} }
if len(entries) != 0 { if len(entries) != 0 {
common.LogInfo1("Setting config vars") common.LogInfo1Quiet("Setting config vars")
fmt.Println(prettyPrintEnvEntries(" ", entries)) if os.Getenv("DOKKU_QUIET_OUTPUT") == "" {
fmt.Println(prettyPrintEnvEntries(" ", entries))
}
env.Write() env.Write()
triggerUpdate(appName, "set", keys) triggerUpdate(appName, "set", keys)
} }
@@ -72,11 +75,11 @@ func UnsetMany(appName string, keys []string, restart bool) (err error) {
} }
for _, k := range keys { for _, k := range keys {
if _, hasKey := env.Map()[k]; hasKey { if _, hasKey := env.Map()[k]; hasKey {
common.LogInfo1(fmt.Sprintf("Unsetting %s", k)) common.LogInfo1Quiet(fmt.Sprintf("Unsetting %s", k))
env.Unset(k) env.Unset(k)
changed = true changed = true
} else { } else {
common.LogInfo1(fmt.Sprintf("Skipping %s, it is not set in the environment", k)) common.LogInfo1Quiet(fmt.Sprintf("Skipping %s, it is not set in the environment", k))
} }
} }
if changed { if changed {