feat: add ability to export env vars as a --env=key ... string
This commit is contained in:
1 parent
33d5dd44d9
commit
5921692f83
4 files changed
+25
-9
No files matched your search
@@ -24,8 +24,10 @@ const (
|
||||
ExportFormatExports ExportFormat = iota
|
||||
//ExportFormatEnvfile format: dotenv file
|
||||
ExportFormatEnvfile
|
||||
//ExportFormatDockerArgs format: --env args for docker
|
||||
//ExportFormatDockerArgs format: --env KEY=VALUE args for docker
|
||||
ExportFormatDockerArgs
|
||||
//ExportFormatDockerArgsKeys format: --env KEY args for docker
|
||||
ExportFormatDockerArgsKeys
|
||||
//ExportFormatShell format: env arguments for shell
|
||||
ExportFormatShell
|
||||
//ExportFormatPretty format: pretty-printed in columns
|
||||
@@ -171,6 +173,8 @@ func (e *Env) Export(format ExportFormat) string {
|
||||
return e.EnvfileString()
|
||||
case ExportFormatDockerArgs:
|
||||
return e.DockerArgsString()
|
||||
case ExportFormatDockerArgsKeys:
|
||||
return e.DockerArgsKeysString()
|
||||
case ExportFormatShell:
|
||||
return e.ShellString()
|
||||
case ExportFormatPretty:
|
||||
@@ -201,6 +205,16 @@ func (e *Env) DockerArgsString() string {
|
||||
return e.stringWithPrefixAndSeparator("--env=", " ")
|
||||
}
|
||||
|
||||
//DockerArgsStringKeys gets the contents of this Env in the form -env=KEY --env...
|
||||
func (e *Env) DockerArgsKeysString() string {
|
||||
keys := e.Keys()
|
||||
entries := make([]string, len(keys))
|
||||
for i, k := range keys {
|
||||
entries[i] = fmt.Sprintf("%s%s", "--env=", k)
|
||||
}
|
||||
return strings.Join(entries, " ")
|
||||
}
|
||||
|
||||
//JSONString returns the contents of this Env as a key/value json object
|
||||
func (e *Env) JSONString() string {
|
||||
data, err := json.Marshal(e.Map())
|
||||
|
||||
Reference in new issue
Block a user