mirror of
https://github.com/dokku/dokku.git
synced 2026-02-24 04:00:36 +01:00
[config] move PrettyPrintEnvEntries
This commit is contained in:
@@ -37,7 +37,7 @@ func SetMany(appName string, entries map[string]string, restart bool) {
|
||||
}
|
||||
if len(entries) != 0 {
|
||||
common.LogInfo1("Setting config vars")
|
||||
fmt.Println(PrettyPrintEnvEntries(" ", entries))
|
||||
fmt.Println(configenv.PrettyPrintEnvEntries(" ", entries))
|
||||
env.Write()
|
||||
args := append([]string{appName, "set"}, keys...)
|
||||
common.PlugnTrigger("post-config-update", args...)
|
||||
|
||||
@@ -60,7 +60,7 @@ func main() {
|
||||
contextName = appName
|
||||
}
|
||||
common.LogInfo2(contextName + " config vars")
|
||||
fmt.Println(config.PrettyPrintEnvEntries("", env.Map()))
|
||||
fmt.Println(env.Export(configenv.Pretty))
|
||||
}
|
||||
case "config:help":
|
||||
case "help":
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
godotenv "github.com/joho/godotenv"
|
||||
"github.com/ryanuber/columnize"
|
||||
)
|
||||
|
||||
//ExportFormat types of possible exports
|
||||
@@ -28,6 +29,8 @@ const (
|
||||
DockerArgs
|
||||
//Shell format: env arguments for shell
|
||||
Shell
|
||||
//Pretty format: pretty-printed in columns
|
||||
Pretty
|
||||
)
|
||||
|
||||
//Env is a representation for global or app environment
|
||||
@@ -52,6 +55,8 @@ func (e *Env) Export(format ExportFormat) string {
|
||||
return e.DockerArgsString()
|
||||
case Shell:
|
||||
return e.ShellString()
|
||||
case Pretty:
|
||||
return PrettyPrintEnvEntries("", e.Map())
|
||||
default:
|
||||
common.LogFail(fmt.Sprintf("Unknown export format: %v", format))
|
||||
return ""
|
||||
@@ -242,3 +247,15 @@ func getAppFile(appName string) (string, error) {
|
||||
func getGlobalFile() string {
|
||||
return filepath.Join(common.MustGetEnv("DOKKU_ROOT"), "ENV")
|
||||
}
|
||||
|
||||
//PrettyPrintEnvEntries in columns
|
||||
func PrettyPrintEnvEntries(prefix string, entries map[string]string) (representation string) {
|
||||
colConfig := columnize.DefaultConfig()
|
||||
colConfig.Prefix = prefix
|
||||
colConfig.Delim = "\x00"
|
||||
lines := make([]string, 0, len(entries))
|
||||
for k, v := range entries {
|
||||
lines = append(lines, fmt.Sprintf("%s:\x00%s", k, v))
|
||||
}
|
||||
return columnize.Format(lines, colConfig)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user