command/fmt: Disable list/write when using STDIN

These options don't make sense when passing STDIN. `-write` will raise an
error because there is no file to write to. `-list` will always say
`<standard input>`. So disable whenever using STDIN, making the command
much simpler:

    cat main.tf | terraform fmt -
This commit is contained in:
Dan Carley 2016-02-02 22:10:23 +00:00
parent e9128769b5
commit 79e2753e41
3 changed files with 10 additions and 10 deletions

View File

@ -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

View File

@ -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())
}

View File

@ -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