From a0cb7c560ec6ac04388e7df3d56c91c2579c5624 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 29 May 2020 04:22:14 -0400 Subject: [PATCH] tests: fix issues with fetching config --- plugins/config/src/subcommands/subcommands.go | 33 ++++++++++++++----- plugins/config/subcommands.go | 10 +++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/plugins/config/src/subcommands/subcommands.go b/plugins/config/src/subcommands/subcommands.go index ea08c54a5..94460a188 100644 --- a/plugins/config/src/subcommands/subcommands.go +++ b/plugins/config/src/subcommands/subcommands.go @@ -24,20 +24,25 @@ func main() { subcommand := parts[len(parts)-1] var err error + var appName string switch subcommand { case "bundle": args := flag.NewFlagSet("config:bundle", flag.ExitOnError) global := args.Bool("global", false, "--global: use the global environment") merged := args.Bool("merged", false, "--merged: merge app environment and global environment") args.Parse(os.Args[2:]) - appName := args.Arg(0) + if !*global { + appName = args.Arg(0) + } err = config.CommandBundle(appName, *global, *merged) case "clear": args := flag.NewFlagSet("config:clear", flag.ExitOnError) global := args.Bool("global", false, "--global: use the global environment") noRestart := args.Bool("no-restart", false, "--no-restart: no restart") args.Parse(os.Args[2:]) - appName := args.Arg(0) + if !*global { + appName = args.Arg(0) + } err = config.CommandClear(appName, *global, *noRestart) case "export": args := flag.NewFlagSet("config:export", flag.ExitOnError) @@ -45,14 +50,18 @@ func main() { merged := args.Bool("merged", false, "--merged: merge app environment and global environment") format := args.String("format", "exports", "--format: [ exports | envfile | docker-args | shell | pretty | json | json-list ] which format to export as)") args.Parse(os.Args[2:]) - appName := args.Arg(0) + if !*global { + appName = args.Arg(0) + } err = config.CommandExport(appName, *global, *merged, *format) case "get": args := flag.NewFlagSet("config:get", flag.ExitOnError) global := args.Bool("global", false, "--global: use the global environment") quoted := args.Bool("quoted", false, "--quoted: get the value quoted") args.Parse(os.Args[2:]) - appName := args.Arg(0) + if !*global { + appName = args.Arg(0) + } keys := getKeys(args.Args(), *global) err = config.CommandGet(appName, keys, *global, *quoted) case "keys": @@ -60,14 +69,18 @@ func main() { global := args.Bool("global", false, "--global: use the global environment") merged := args.Bool("merged", false, "--merged: merge app environment and global environment") args.Parse(os.Args[2:]) - appName := args.Arg(0) + if !*global { + appName = args.Arg(0) + } err = config.CommandKeys(appName, *global, *merged) case "show": args := flag.NewFlagSet("config:show", flag.ExitOnError) global := args.Bool("global", false, "--global: use the global environment") merged := args.Bool("merged", false, "--merged: display the app's environment merged with the global environment") args.Parse(os.Args[2:]) - appName := args.Arg(0) + if !*global { + appName = args.Arg(0) + } err = config.CommandShow(appName, *global, *merged, false, false) case "set": args := flag.NewFlagSet("config:set", flag.ExitOnError) @@ -75,7 +88,9 @@ func main() { encoded := args.Bool("encoded", false, "--encoded: interpret VALUEs as base64") noRestart := args.Bool("no-restart", false, "--no-restart: no restart") args.Parse(os.Args[2:]) - appName := args.Arg(0) + if !*global { + appName = args.Arg(0) + } pairs := getKeys(args.Args(), *global) err = config.CommandSet(appName, pairs, *global, *noRestart, *encoded) case "unset": @@ -83,7 +98,9 @@ func main() { global := args.Bool("global", false, "--global: use the global environment") noRestart := args.Bool("no-restart", false, "--no-restart: no restart") args.Parse(os.Args[2:]) - appName := args.Arg(0) + if !*global { + appName = args.Arg(0) + } keys := getKeys(args.Args(), *global) err = config.CommandUnset(appName, keys, *global, *noRestart) default: diff --git a/plugins/config/subcommands.go b/plugins/config/subcommands.go index 0f3541a87..b610eade4 100644 --- a/plugins/config/subcommands.go +++ b/plugins/config/subcommands.go @@ -73,16 +73,18 @@ func CommandGet(appName string, keys []string, global bool, quoted bool) error { return err } - if len(keys) != 1 { - return fmt.Errorf("Unexpected argument(s): %v", keys[1:]) - } if len(keys) == 0 { return errors.New("Expected: key") } + if len(keys) != 1 { + return fmt.Errorf("Unexpected argument(s): %v", keys[1:]) + } + value, ok := Get(appName, keys[0]) if !ok { - return fmt.Errorf("No value for key %v", keys[0]) + os.Exit(1) + return nil } if quoted {