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:
parent
9f3bbd249c
commit
fa7b922e7a
22
main.go
22
main.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue