command: use bufio.ReadString instead of scanning to get spaces
[GH-2628]
This commit is contained in:
parent
29e6570df8
commit
2ac142abc3
|
@ -11,6 +11,7 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/mitchellh/colorstring"
|
"github.com/mitchellh/colorstring"
|
||||||
|
@ -95,12 +96,13 @@ func (i *UIInput) Input(opts *terraform.InputOpts) (string, error) {
|
||||||
// interrupt this if we are interrupted (SIGINT)
|
// interrupt this if we are interrupted (SIGINT)
|
||||||
result := make(chan string, 1)
|
result := make(chan string, 1)
|
||||||
go func() {
|
go func() {
|
||||||
var line string
|
buf := bufio.NewReader(r)
|
||||||
if _, err := fmt.Fscanln(r, &line); err != nil {
|
line, err := buf.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
log.Printf("[ERR] UIInput scan err: %s", err)
|
log.Printf("[ERR] UIInput scan err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
result <- line
|
result <- strings.TrimRightFunc(line, unicode.IsSpace)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
|
@ -26,3 +26,19 @@ func TestUIInputInput(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v", v)
|
t.Fatalf("bad: %#v", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUIInputInput_spaces(t *testing.T) {
|
||||||
|
i := &UIInput{
|
||||||
|
Reader: bytes.NewBufferString("foo bar\n"),
|
||||||
|
Writer: bytes.NewBuffer(nil),
|
||||||
|
}
|
||||||
|
|
||||||
|
v, err := i.Input(&terraform.InputOpts{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v != "foo bar" {
|
||||||
|
t.Fatalf("bad: %#v", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue