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:
Dan Carley 2016-02-02 22:10:22 +00:00
parent cc41c7cfa0
commit c753390399
3 changed files with 7 additions and 7 deletions

View File

@ -24,8 +24,8 @@ func (c *FmtCommand) Run(args []string) int {
args = c.Meta.process(args, false)
cmdFlags := flag.NewFlagSet("fmt", flag.ContinueOnError)
cmdFlags.BoolVar(&c.opts.List, "list", false, "list")
cmdFlags.BoolVar(&c.opts.Write, "write", false, "write")
cmdFlags.BoolVar(&c.opts.List, "list", true, "list")
cmdFlags.BoolVar(&c.opts.Write, "write", true, "write")
cmdFlags.BoolVar(&c.opts.Diff, "diff", false, "diff")
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }

View File

@ -1,7 +1,7 @@
package command
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -88,8 +88,8 @@ func TestFmt_workingDirectory(t *testing.T) {
t.Fatalf("wrong exit code. errors: \n%s", ui.ErrorWriter.String())
}
expected := fmtFixture.golden
if actual := ui.OutputWriter.Bytes(); !bytes.Equal(actual, expected) {
expected := fmt.Sprintf("%s\n", fmtFixture.filename)
if actual := ui.OutputWriter.String(); actual != expected {
t.Fatalf("got: %q\nexpected: %q", actual, expected)
}
}

View File

@ -19,6 +19,6 @@ Usage: `terraform fmt [options] [DIR]`
The command-line flags are all optional. The list of available flags are:
* `-list=false` - List files whose formatting differs
* `-write=false` - Write result to source file instead of STDOUT
* `-list=true` - List files whose formatting differs
* `-write=true` - Write result to source file instead of STDOUT
* `-diff=false` - Display diffs instead of rewriting files