main.go: don't set TTY interface from tty.Open() in case open fails

If tty.Open fails the return tty is still nil, but the interface type will be set; meaning in go that `TTY == nil` will always be false.

fix #7506
This commit is contained in:
Adrien Delorme 2019-04-17 11:49:02 +02:00
parent 9f3bbd249c
commit fa7b922e7a
1 changed files with 10 additions and 12 deletions

22
main.go
View File

@ -186,21 +186,19 @@ func wrappedMain() int {
return 1
}
} else {
var TTY packer.TTY
if !inPlugin {
var err error
TTY, err = tty.Open()
if err != nil {
fmt.Fprintf(os.Stderr, "No tty available: %s\n", err)
} else {
defer TTY.Close()
}
}
ui = &packer.BasicUi{
basicUi := &packer.BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stdout,
TTY: TTY,
}
ui = basicUi
if !inPlugin {
if TTY, err := tty.Open(); err != nil {
fmt.Fprintf(os.Stderr, "No tty available: %s\n", err)
} else {
basicUi.TTY = TTY
defer TTY.Close()
}
}
}
// Create the CLI meta