diff --git a/command/fmt.go b/command/fmt.go index f0a7bfa79..d9ccc2643 100644 --- a/command/fmt.go +++ b/command/fmt.go @@ -51,7 +51,10 @@ func (c *FmtCommand) Run(args []string) int { var dirs []string if len(args) == 0 { dirs = []string{"."} - } else if args[0] != stdinArg { + } else if args[0] == stdinArg { + c.opts.List = false + c.opts.Write = false + } else { dirs = []string{args[0]} } @@ -76,9 +79,9 @@ Usage: terraform fmt [options] [DIR] Options: - -list List files whose formatting differs + -list List files whose formatting differs (disabled if using STDIN) - -write Write result to source file instead of STDOUT + -write Write result to source file instead of STDOUT (disabled if using STDIN) -diff Display diffs instead of rewriting files diff --git a/command/fmt_test.go b/command/fmt_test.go index de117bb2c..0a7f26fdb 100644 --- a/command/fmt_test.go +++ b/command/fmt_test.go @@ -137,11 +137,7 @@ func TestFmt_stdinArg(t *testing.T) { input: input, } - args := []string{ - "-write=false", - "-list=false", - "-", - } + args := []string{"-"} if code := c.Run(args); code != 0 { t.Fatalf("wrong exit code. errors: \n%s", ui.ErrorWriter.String()) } diff --git a/website/source/docs/commands/fmt.html.markdown b/website/source/docs/commands/fmt.html.markdown index 9f33e98e3..bb48ae957 100644 --- a/website/source/docs/commands/fmt.html.markdown +++ b/website/source/docs/commands/fmt.html.markdown @@ -22,6 +22,7 @@ input (STDIN). The command-line flags are all optional. The list of available flags are: -* `-list=true` - List files whose formatting differs -* `-write=true` - Write result to source file instead of STDOUT +* `-list=true` - List files whose formatting differs (disabled if using STDIN) +* `-write=true` - Write result to source file instead of STDOUT (disabled if + using STDIN) * `-diff=false` - Display diffs instead of rewriting files