From 546865e1ee593e4853aaa9835abb37777878052d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 8 Sep 2014 20:56:18 -0700 Subject: [PATCH] command: make sure errors from flag go to UI [GH-269] --- CHANGELOG.md | 1 + command/meta.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db03ab0bf..286a86238 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/command/meta.go b/command/meta.go index f5922c589..fea12a095 100644 --- a/command/meta.go +++ b/command/meta.go @@ -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 }