From 851efe3ce0c038cc3404a37dcc7a92d986940fe6 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 21 Jul 2022 02:44:36 +0200 Subject: [PATCH] fix: Fix dropping of input when prompting for multiple values from piped stdin --- pkg/cmd/config.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/config.go b/pkg/cmd/config.go index 232ec050e78..3b68df5d5f4 100644 --- a/pkg/cmd/config.go +++ b/pkg/cmd/config.go @@ -182,9 +182,10 @@ type Config struct { homeDirAbsPath chezmoi.AbsPath encryption chezmoi.Encryption - stdin io.Reader - stdout io.Writer - stderr io.Writer + stdin io.Reader + stdout io.Writer + stderr io.Writer + bufioReader *bufio.Reader tempDirs map[string]chezmoi.AbsPath @@ -1842,7 +1843,10 @@ func (c *Config) readLine(prompt string) (string, error) { if err != nil { return "", err } - line, err := bufio.NewReader(c.stdin).ReadString('\n') + if c.bufioReader == nil { + c.bufioReader = bufio.NewReader(c.stdin) + } + line, err := c.bufioReader.ReadString('\n') if err != nil { return "", err }