[config] support for env bundles

This commit is contained in:
Alex Quick
2017-04-22 15:58:03 -04:00
parent fd27d90303
commit c20fbfccf6
4 changed files with 62 additions and 32 deletions

View File

@@ -12,13 +12,16 @@ import (
// print the environment to stdout
func main() {
const defaultPrefix = "export "
const defaultSeparator = "\n"
args := flag.NewFlagSet("config:export", flag.ExitOnError)
global := args.Bool("global", false, "--global: use the global environment")
merged := args.Bool("merged", false, "--merged: merge app environment and global environment")
keys := args.Bool("keys", false, "--keys: export keys only")
bundle := args.Bool("bundle", false, "--bundle: export as tar bundle")
envfile := args.Bool("envfile", false, "--envfile: export as envfile rather than bash exports (--prefix='')")
prefix := args.String("prefix", "export ", "--prefix: prefix")
separator := args.String("separator", "\n", "--separator: separator")
prefix := args.String("prefix", defaultPrefix, "--prefix: prefix")
separator := args.String("separator", defaultSeparator, "--separator: separator")
escapeNewlines := args.Bool("escape-newlines", false, "--escape-newlines: replace literal newlines with $'\n'")
args.Parse(os.Args[2:])
appName := args.Arg(0)
@@ -57,6 +60,16 @@ func main() {
return
}
if *escapeNewlines {
env.EscapeNewlines = true
}
if *bundle {
if *prefix != defaultPrefix || *separator != defaultSeparator || *envfile {
common.LogFail("--bundle cannot be given with --envfile, --prefix, or --separator")
}
env.ExportBundle(os.Stdout)
}
if *envfile {
if *prefix != defaultPrefix {
common.LogFail("--prefix and --envfile cannot both be given")