Skip to content

Commit

Permalink
feat: spec (#26)
Browse files Browse the repository at this point in the history
* feat: spec

* surround vars in quotes

* add threads option
  • Loading branch information
rssnyder authored Jan 26, 2023
1 parent 13404ac commit fbb8ad1
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Args struct {
Target string `envconfig:"PLUGIN_TARGET"`
Retries int `envconfig:"PLUGIN_RETRIES"`
Flat string `envconfig:"PLUGIN_FLAT"`
Spec string `envconfig:"PLUGIN_SPEC"`
Threads int `envconfig:"PLUGIN_THREADS"`
SpecVars string `envconfig:"PLUGIN_SPEC_VARS"`
}

// Exec executes the plugin.
Expand Down Expand Up @@ -61,13 +64,26 @@ func Exec(ctx context.Context, args Args) error {
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")
if args.Threads > 0 {
cmdArgs = append(cmdArgs, fmt.Sprintf("--threads=%d", args.Threads))
}
if args.Target == "" {
return fmt.Errorf("target path needs to be set")

// Take in spec file or use source/target arguments
if args.Spec != "" {
cmdArgs = append(cmdArgs, fmt.Sprintf("--spec=%s", args.Spec))
if args.SpecVars != "" {
cmdArgs = append(cmdArgs, fmt.Sprintf("--spec-vars='%s'", args.SpecVars))
}
} else {
if args.Source == "" {
return fmt.Errorf("source file needs to be set")
}
if args.Target == "" {
return fmt.Errorf("target path needs to be set")
}
cmdArgs = append(cmdArgs, fmt.Sprintf("\"%s\"", args.Source), args.Target)
}
cmdArgs = append(cmdArgs, fmt.Sprintf("\"%s\"", args.Source), args.Target)

cmdStr := strings.Join(cmdArgs[:], " ")

shell, shArg := getShell()
Expand Down

0 comments on commit fbb8ad1

Please sign in to comment.