[config] add config:export --format shell
This commit is contained in:
1 parent
e7a81a8f8b
commit
4f5c747c99
3 files changed
+22
-2
No files matched your search
@@ -16,12 +16,18 @@ import (
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
//ExportFormat types of possible exports
|
||||
type ExportFormat int
|
||||
|
||||
const (
|
||||
//Exports format: Sourceable exports
|
||||
Exports ExportFormat = iota
|
||||
//Envfile format: dotenv file
|
||||
Envfile
|
||||
//DockerArgs format: --env args for docker
|
||||
DockerArgs
|
||||
//Shell format: env arguments for shell
|
||||
Shell
|
||||
)
|
||||
|
||||
//Env is a representation for global or app environment
|
||||
@@ -35,6 +41,7 @@ func (e *Env) String() string {
|
||||
return e.EnvfileString()
|
||||
}
|
||||
|
||||
//Export the Env in the given format
|
||||
func (e *Env) Export(format ExportFormat) string {
|
||||
switch format {
|
||||
case Exports:
|
||||
@@ -43,6 +50,8 @@ func (e *Env) Export(format ExportFormat) string {
|
||||
return e.EnvfileString()
|
||||
case DockerArgs:
|
||||
return e.DockerArgsString()
|
||||
case Shell:
|
||||
return e.ShellString()
|
||||
default:
|
||||
common.LogFail(fmt.Sprintf("Unknown export format: %v", format))
|
||||
return ""
|
||||
@@ -65,6 +74,12 @@ func (e *Env) DockerArgsString() string {
|
||||
return e.stringWithPrefixAndSeparator("--env=", " ", true)
|
||||
}
|
||||
|
||||
//ShellString gets the contents of this Env in the form "KEY='value' KEY2='value'"
|
||||
// for passing the environment in the shell
|
||||
func (e *Env) ShellString() string {
|
||||
return e.stringWithPrefixAndSeparator("", " ", true)
|
||||
}
|
||||
|
||||
//StringWithPrefixAndSeparator makes a string of the environment
|
||||
// with the given prefix and separator for each entry
|
||||
func (e *Env) stringWithPrefixAndSeparator(prefix string, separator string, allowNewlines bool) string {
|
||||
|
||||
Reference in new issue
Block a user