command/fmt: Default write and list to true
The most common usage usage will be enabling the `-write` and `-list` options so that files are updated in place and a list of any modified files is printed. This matches the default behaviour of `go fmt` (not `gofmt`). So enable these options by default. This does mean that you will have to explicitly disable these if you want to generate valid patches, e.g. `terraform fmt -diff -write=false -list=false`
This commit is contained in:
parent
cc41c7cfa0
commit
c753390399
|
@ -24,8 +24,8 @@ func (c *FmtCommand) Run(args []string) int {
|
||||||
args = c.Meta.process(args, false)
|
args = c.Meta.process(args, false)
|
||||||
|
|
||||||
cmdFlags := flag.NewFlagSet("fmt", flag.ContinueOnError)
|
cmdFlags := flag.NewFlagSet("fmt", flag.ContinueOnError)
|
||||||
cmdFlags.BoolVar(&c.opts.List, "list", false, "list")
|
cmdFlags.BoolVar(&c.opts.List, "list", true, "list")
|
||||||
cmdFlags.BoolVar(&c.opts.Write, "write", false, "write")
|
cmdFlags.BoolVar(&c.opts.Write, "write", true, "write")
|
||||||
cmdFlags.BoolVar(&c.opts.Diff, "diff", false, "diff")
|
cmdFlags.BoolVar(&c.opts.Diff, "diff", false, "diff")
|
||||||
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -88,8 +88,8 @@ func TestFmt_workingDirectory(t *testing.T) {
|
||||||
t.Fatalf("wrong exit code. errors: \n%s", ui.ErrorWriter.String())
|
t.Fatalf("wrong exit code. errors: \n%s", ui.ErrorWriter.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := fmtFixture.golden
|
expected := fmt.Sprintf("%s\n", fmtFixture.filename)
|
||||||
if actual := ui.OutputWriter.Bytes(); !bytes.Equal(actual, expected) {
|
if actual := ui.OutputWriter.String(); actual != expected {
|
||||||
t.Fatalf("got: %q\nexpected: %q", actual, expected)
|
t.Fatalf("got: %q\nexpected: %q", actual, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,6 @@ Usage: `terraform fmt [options] [DIR]`
|
||||||
|
|
||||||
The command-line flags are all optional. The list of available flags are:
|
The command-line flags are all optional. The list of available flags are:
|
||||||
|
|
||||||
* `-list=false` - List files whose formatting differs
|
* `-list=true` - List files whose formatting differs
|
||||||
* `-write=false` - Write result to source file instead of STDOUT
|
* `-write=true` - Write result to source file instead of STDOUT
|
||||||
* `-diff=false` - Display diffs instead of rewriting files
|
* `-diff=false` - Display diffs instead of rewriting files
|
||||||
|
|
Loading…
Reference in New Issue