20 lines
431 B
Go
20 lines
431 B
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
func (a App) confirmAction(question string, yes bool) error {
|
|
if yes {
|
|
return nil
|
|
}
|
|
fmt.Fprint(a.Err, question+" [y/N]: ")
|
|
line, _ := bufio.NewReader(a.In).ReadString('\n')
|
|
if answer := strings.ToLower(strings.TrimSpace(line)); answer != "y" && answer != "yes" {
|
|
return fmt.Errorf("action canceled; use --yes for explicit non-interactive confirmation")
|
|
}
|
|
return nil
|
|
}
|