Skip to content

Commit

Permalink
add option to apply flat heirarchy (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
raghavharness authored Jul 20, 2022
1 parent 697d1a4 commit 6d9b3f1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"runtime"
"strconv"
"strings"
)

Expand All @@ -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.
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6d9b3f1

Please sign in to comment.