Browse Source

added recursive flag to fmt

pull/131/head
Mustafa Babil 4 years ago
parent
commit
05a1a6f476
  1. 4
      DOCS.md
  2. 4
      plugin.go
  3. 8
      plugin_test.go

4
DOCS.md

@ -194,6 +194,7 @@ pipeline:
+ write: false
+ diff: true
+ check: true
+ recursive: true
```
You may want to run some executions in parallel without having racing condition problems with the .terraform dir and
@ -244,6 +245,9 @@ fmt_options.diff
fmt_options.check
: Check if the input is formatted. Exit status will be 0 if all input is properly formatted and non-zero otherwise. Default `false`.
fmt_options.recursive
: Process files in subdirectories as well. Default `false`.
vars
: a map of variables to pass to the Terraform `plan` and `apply` commands.
Each value is passed as a `-var <key>=<value>` option.

4
plugin.go

@ -57,6 +57,7 @@ type (
Write *bool `json:"write"`
Diff *bool `json:"diff"`
Check *bool `json:"check"`
Recursive *bool `json:"recursive"`
}
// Plugin represents the plugin instance to be executed
@ -364,6 +365,9 @@ func tfFmt(config Config) *exec.Cmd {
if config.FmtOptions.Check != nil {
args = append(args, fmt.Sprintf("-check=%t", *config.FmtOptions.Check))
}
if config.FmtOptions.Recursive != nil {
args = append(args, fmt.Sprintf("-recursive=%t", *config.FmtOptions.Recursive))
}
return exec.Command(
"terraform",
args...,

8
plugin_test.go

@ -243,6 +243,11 @@ func TestPlugin(t *testing.T) {
args{config: Config{FmtOptions: FmtOptions{Check: &affirmative}}},
exec.Command("terraform", "fmt", "-check=true"),
},
{
"with recursive",
args{config: Config{FmtOptions: FmtOptions{Recursive: &affirmative}}},
exec.Command("terraform", "fmt", "-recursive=true"),
},
{
"with combination",
args{config: Config{FmtOptions: FmtOptions{
@ -250,8 +255,9 @@ func TestPlugin(t *testing.T) {
Write: &negative,
Diff: &affirmative,
Check: &affirmative,
Recursive: &affirmative,
}}},
exec.Command("terraform", "fmt", "-list=false", "-write=false", "-diff=true", "-check=true"),
exec.Command("terraform", "fmt", "-list=false", "-write=false", "-diff=true", "-check=true", "-recursive=true"),
},
}

Loading…
Cancel
Save