Files
dokku/plugins/config/src/subcommands/export/export.go
2017-09-27 23:56:40 -04:00

49 lines
1.0 KiB
Go

package main
import (
"flag"
"fmt"
"os"
common "github.com/dokku/dokku/plugins/common"
"github.com/dokku/dokku/plugins/config/src/configenv"
)
// print the environment to stdout
func main() {
args := flag.NewFlagSet("config:export", flag.ExitOnError)
global := args.Bool("global", false, "--global: use the global environment")
keys := args.Bool("keys", false, "--keys: export keys only")
envfile := args.Bool("envfile", false, "--envfile: export as envfile rather than bash exports")
args.Parse(os.Args[2:])
appName := args.Arg(0)
if appName == "" && !*global {
common.LogFail("Please specify an app or --global")
}
if *global {
if appName != "" {
common.LogFail("Trailing argument: " + appName)
}
appName = "--global"
}
env, err := configenv.NewFromTarget(appName)
if err != nil {
common.LogFail(err.Error())
}
if *keys {
for _, k := range env.Keys() {
fmt.Println(k)
}
return
}
if *envfile {
fmt.Println(env.EnvfileString())
} else {
fmt.Println(env.ExportfileString())
}
}