[config] config:export --merge, --prefix, & --suffix
This commit is contained in:
@@ -11,10 +11,14 @@ import (
|
||||
|
||||
// print the environment to stdout
|
||||
func main() {
|
||||
const defaultPrefix = "export "
|
||||
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")
|
||||
envfile := args.Bool("envfile", false, "--envfile: export as envfile rather than bash exports")
|
||||
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")
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
appName := args.Arg(0)
|
||||
@@ -26,6 +30,9 @@ func main() {
|
||||
if appName != "" {
|
||||
common.LogFail("Trailing argument: " + appName)
|
||||
}
|
||||
if *merged == true {
|
||||
common.LogFail("Only app environments can be merged")
|
||||
}
|
||||
appName = "--global"
|
||||
}
|
||||
|
||||
@@ -33,6 +40,16 @@ func main() {
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
if *merged {
|
||||
global, err := configenv.LoadGlobal()
|
||||
if err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
global.Merge(env)
|
||||
env = global
|
||||
}
|
||||
|
||||
if *keys {
|
||||
for _, k := range env.Keys() {
|
||||
fmt.Println(k)
|
||||
@@ -41,8 +58,11 @@ func main() {
|
||||
}
|
||||
|
||||
if *envfile {
|
||||
fmt.Println(env.EnvfileString())
|
||||
} else {
|
||||
fmt.Println(env.ExportfileString())
|
||||
if *prefix != defaultPrefix {
|
||||
common.LogFail("--prefix and --envfile cannot both be given")
|
||||
return
|
||||
}
|
||||
*prefix = ""
|
||||
}
|
||||
fmt.Println(env.StringWithPrefixAndSeparator(*prefix, *separator))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user