[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 {
|
if len(entries) != 0 {
|
||||||
common.LogInfo1("Setting config vars")
|
common.LogInfo1("Setting config vars")
|
||||||
fmt.Println(PrettyPrintEnvEntries(" ", entries))
|
fmt.Println(configenv.PrettyPrintEnvEntries(" ", entries))
|
||||||
env.Write()
|
env.Write()
|
||||||
args := append([]string{appName, "set"}, keys...)
|
args := append([]string{appName, "set"}, keys...)
|
||||||
common.PlugnTrigger("post-config-update", args...)
|
common.PlugnTrigger("post-config-update", args...)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func main() {
|
|||||||
contextName = appName
|
contextName = appName
|
||||||
}
|
}
|
||||||
common.LogInfo2(contextName + " config vars")
|
common.LogInfo2(contextName + " config vars")
|
||||||
fmt.Println(config.PrettyPrintEnvEntries("", env.Map()))
|
fmt.Println(env.Export(configenv.Pretty))
|
||||||
}
|
}
|
||||||
case "config:help":
|
case "config:help":
|
||||||
case "help":
|
case "help":
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
common "github.com/dokku/dokku/plugins/common"
|
common "github.com/dokku/dokku/plugins/common"
|
||||||
godotenv "github.com/joho/godotenv"
|
godotenv "github.com/joho/godotenv"
|
||||||
|
"github.com/ryanuber/columnize"
|
||||||
)
|
)
|
||||||
|
|
||||||
//ExportFormat types of possible exports
|
//ExportFormat types of possible exports
|
||||||
@@ -28,6 +29,8 @@ const (
|
|||||||
DockerArgs
|
DockerArgs
|
||||||
//Shell format: env arguments for shell
|
//Shell format: env arguments for shell
|
||||||
Shell
|
Shell
|
||||||
|
//Pretty format: pretty-printed in columns
|
||||||
|
Pretty
|
||||||
)
|
)
|
||||||
|
|
||||||
//Env is a representation for global or app environment
|
//Env is a representation for global or app environment
|
||||||
@@ -52,6 +55,8 @@ func (e *Env) Export(format ExportFormat) string {
|
|||||||
return e.DockerArgsString()
|
return e.DockerArgsString()
|
||||||
case Shell:
|
case Shell:
|
||||||
return e.ShellString()
|
return e.ShellString()
|
||||||
|
case Pretty:
|
||||||
|
return PrettyPrintEnvEntries("", e.Map())
|
||||||
default:
|
default:
|
||||||
common.LogFail(fmt.Sprintf("Unknown export format: %v", format))
|
common.LogFail(fmt.Sprintf("Unknown export format: %v", format))
|
||||||
return ""
|
return ""
|
||||||
@@ -242,3 +247,15 @@ func getAppFile(appName string) (string, error) {
|
|||||||
func getGlobalFile() string {
|
func getGlobalFile() string {
|
||||||
return filepath.Join(common.MustGetEnv("DOKKU_ROOT"), "ENV")
|
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