Skip to content

Commit

Permalink
Support postional arg (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
osterman authored Jan 19, 2019
1 parent 962bbca commit 0087f40
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func main() {
var tfCliArgs []string

reTfCliInitBackend := regexp.MustCompile("^TF_CLI_INIT_BACKEND_CONFIG_(.*)")
reTfCliCommand := regexp.MustCompile("^TF_CLI_(INIT|PLAN|APPLY|DESTROY)_(.*)")
reTfCliOption := regexp.MustCompile("^TF_CLI_(INIT|PLAN|APPLY|DESTROY)_(.*)")
reTfCliPositional := regexp.MustCompile("^TF_CLI_(INIT|PLAN|APPLY|DESTROY)$")
reTfCliDefault := regexp.MustCompile("^TF_CLI_DEFAULT_(.*)")

reTfVar := regexp.MustCompile("^" + tfenvPrefix)
Expand Down Expand Up @@ -84,9 +85,9 @@ func main() {
arg += "=" + pair[1]
}
tfCliArgsInit = append(tfCliArgsInit, arg)
} else if reTfCliCommand.MatchString(pair[0]) {
} else if reTfCliOption.MatchString(pair[0]) {
// `TF_CLI_ARGS_plan`: Map `TF_CLI_PLAN_SOMETHING=value` to `-something=value`
match := reTfCliCommand.FindStringSubmatch(pair[0])
match := reTfCliOption.FindStringSubmatch(pair[0])
cmd := reUnderscores.ReplaceAllString(match[1], "-")
cmd = strings.ToLower(cmd)

Expand All @@ -99,13 +100,33 @@ func main() {
}
switch cmd {
case "init":
tfCliArgsInit = append(tfCliArgsInit, arg)
tfCliArgsInit = append([]string{arg}, tfCliArgsInit...)
case "plan":
tfCliArgsPlan = append(tfCliArgsPlan, arg)
tfCliArgsPlan = append([]string{arg}, tfCliArgsPlan...)
case "apply":
tfCliArgsApply = append(tfCliArgsApply, arg)
tfCliArgsApply = append([]string{arg}, tfCliArgsApply...)
case "destroy":
tfCliArgsDestroy = append(tfCliArgsDestroy, arg)
tfCliArgsDestroy = append([]string{arg}, tfCliArgsDestroy...)
}
} else if reTfCliPositional.MatchString(pair[0]) {
// `TF_CLI_ARGS_plan`: Map `TF_CLI_PLAN=value` to `value` for `plan`
match := reTfCliPositional.FindStringSubmatch(pair[0])
cmd := reUnderscores.ReplaceAllString(match[1], "-")
cmd = strings.ToLower(cmd)

arg := pair[1]
// Append non-empty parameters or non-true values.
if len(arg) > 0 {
switch cmd {
case "init":
tfCliArgsInit = append(tfCliArgsInit, arg)
case "plan":
tfCliArgsPlan = append(tfCliArgsPlan, arg)
case "apply":
tfCliArgsApply = append(tfCliArgsApply, arg)
case "destroy":
tfCliArgsDestroy = append(tfCliArgsDestroy, arg)
}
}
} else if reTfCliDefault.MatchString(pair[0]) {
// `TF_CLI_ARGS`: Map `TF_CLI_DEFAULT_SOMETHING=value` to `-something=value`
Expand Down

0 comments on commit 0087f40

Please sign in to comment.