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:
parent
e9128769b5
commit
79e2753e41
|
@ -51,7 +51,10 @@ func (c *FmtCommand) Run(args []string) int {
|
||||||
var dirs []string
|
var dirs []string
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
dirs = []string{"."}
|
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]}
|
dirs = []string{args[0]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,9 +79,9 @@ Usage: terraform fmt [options] [DIR]
|
||||||
|
|
||||||
Options:
|
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 Display diffs instead of rewriting files
|
||||||
|
|
||||||
|
|
|
@ -137,11 +137,7 @@ func TestFmt_stdinArg(t *testing.T) {
|
||||||
input: input,
|
input: input,
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{"-"}
|
||||||
"-write=false",
|
|
||||||
"-list=false",
|
|
||||||
"-",
|
|
||||||
}
|
|
||||||
if code := c.Run(args); code != 0 {
|
if code := c.Run(args); code != 0 {
|
||||||
t.Fatalf("wrong exit code. errors: \n%s", ui.ErrorWriter.String())
|
t.Fatalf("wrong exit code. errors: \n%s", ui.ErrorWriter.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ input (STDIN).
|
||||||
|
|
||||||
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=true` - List files whose formatting differs
|
* `-list=true` - List files whose formatting differs (disabled if using STDIN)
|
||||||
* `-write=true` - Write result to source file instead of STDOUT
|
* `-write=true` - Write result to source file instead of STDOUT (disabled if
|
||||||
|
using STDIN)
|
||||||
* `-diff=false` - Display diffs instead of rewriting files
|
* `-diff=false` - Display diffs instead of rewriting files
|
||||||
|
|
Loading…
Reference in New Issue