@ -160,13 +160,6 @@ type Meta struct {
forceInitCopy bool
reconfigure bool
// errWriter is the write side of a pipe for the FlagSet output. We need to
// keep track of this to close previous pipes between tests. Normal
// operation never needs to close this.
errWriter * io . PipeWriter
// done chan to wait for the scanner goroutine
errScannerDone chan struct { }
// Used with the import command to allow import of state when no matching config exists.
allowMissingConfig bool
}
@ -339,23 +332,16 @@ func (m *Meta) flagSet(n string) *flag.FlagSet {
// 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.
// If a previous pipe exists, we need to close that first.
// This should only happen in testing.
if m . errWriter != nil {
m . errWriter . Close ( )
}
if m . errScannerDone != nil {
<- m . errScannerDone
}
errR , errW := io . Pipe ( )
errScanner := bufio . NewScanner ( errR )
m . errWriter = errW
m . errScannerDone = make ( chan struct { } )
go func ( ) {
defer close ( m . errScannerDone )
// This only needs to be alive long enough to write the help info if
// there is a flag error. Kill the scanner after a short duriation to
// prevent these from accumulating during tests, and cluttering up the
// stack traces.
time . AfterFunc ( 2 * time . Second , func ( ) {
errW . Close ( )
} )
for errScanner . Scan ( ) {
m . Ui . Error ( errScanner . Text ( ) )
}