command: make sure errors from flag go to UI [GH-269]

This commit is contained in:
Mitchell Hashimoto 2014-09-08 20:56:18 -07:00
parent 7b96a9fa06
commit 546865e1ee
2 changed files with 16 additions and 0 deletions

View File

@ -12,6 +12,7 @@ BUG FIXES:
* core: Fix certain syntax of configuration that could cause hang. [GH-261]
* core: `-no-color` flag properly disables color. [GH-250]
* core: "~" is expanded in `-var-file` flags. [GH-273]
* core: Errors with tfvars are shown in console. [GH-269]
* providers/aws: Refreshing EIP from pre-0.2 state file won't error. [GH-258]
* providers/google: Attaching a disk source (not an image) works
properly. [GH-254]

View File

@ -1,8 +1,10 @@
package command
import (
"bufio"
"flag"
"fmt"
"io"
"math/rand"
"os"
@ -137,6 +139,19 @@ func (m *Meta) flagSet(n string) *flag.FlagSet {
f.Var((*FlagVarFile)(&m.autoVariables), m.autoKey, "variable file")
}
// Create an io.Writer that writes to our Ui properly for errors.
// This is kind of a hack, but it does the job. Basically: create
// a pipe, use a scanner to break it into lines, and output each line
// to the UI. Do this forever.
errR, errW := io.Pipe()
errScanner := bufio.NewScanner(errR)
go func() {
for errScanner.Scan() {
m.Ui.Error(errScanner.Text())
}
}()
f.SetOutput(errW)
return f
}