From c753390399843953755ef63483a086fd3ab3708d Mon Sep 17 00:00:00 2001 From: Dan Carley Date: Tue, 2 Feb 2016 22:10:22 +0000 Subject: [PATCH] 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` --- command/fmt.go | 4 ++-- command/fmt_test.go | 6 +++--- website/source/docs/commands/fmt.html.markdown | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/command/fmt.go b/command/fmt.go index e4e9aad2f..49e06c08e 100644 --- a/command/fmt.go +++ b/command/fmt.go @@ -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()) } diff --git a/command/fmt_test.go b/command/fmt_test.go index 3d284e466..d38d54644 100644 --- a/command/fmt_test.go +++ b/command/fmt_test.go @@ -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) } } diff --git a/website/source/docs/commands/fmt.html.markdown b/website/source/docs/commands/fmt.html.markdown index 383f58d1d..7e5d7647b 100644 --- a/website/source/docs/commands/fmt.html.markdown +++ b/website/source/docs/commands/fmt.html.markdown @@ -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