From 6d9b3f1677046af653d09a00e4b3dd7042edb455 Mon Sep 17 00:00:00 2001 From: Raghav Date: Wed, 20 Jul 2022 17:57:06 +0530 Subject: [PATCH] add option to apply flat heirarchy (#24) --- plugin/plugin.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugin/plugin.go b/plugin/plugin.go index 5481c88..404c902 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "runtime" + "strconv" "strings" ) @@ -29,6 +30,7 @@ type Args struct { Source string `envconfig:"PLUGIN_SOURCE"` Target string `envconfig:"PLUGIN_TARGET"` Retries int `envconfig:"PLUGIN_RETRIES"` + Flat string `envconfig:"PLUGIN_FLAT"` } // Exec executes the plugin. @@ -56,6 +58,9 @@ func Exec(ctx context.Context, args Args) error { return fmt.Errorf("either username/password, api key or access token needs to be set") } + flat := parseBoolOrDefault(false, args.Flat) + cmdArgs = append(cmdArgs, fmt.Sprintf("--flat=%s", strconv.FormatBool(flat))) + if args.Source == "" { return fmt.Errorf("source file needs to be set") } @@ -101,6 +106,16 @@ func getEnvPrefix() string { return "$" } +func parseBoolOrDefault(defaultValue bool, s string) (result bool) { + var err error + result, err = strconv.ParseBool(s) + if err != nil { + result = defaultValue + } + + return +} + // trace writes each command to stdout with the command wrapped in an xml // tag so that it can be extracted and displayed in the logs. func trace(cmd *exec.Cmd) {