code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/flags/force.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package flags 17 18 import ( 19 "bufio" 20 "fmt" 21 "os" 22 "strings" 23 ) 24 25 func AreYouSure() bool { 26 return YesOrNo("Are you sure?") 27 } 28 29 func DoYouApproveTx() bool { 30 return YesOrNo("Do you approve this transaction?") 31 } 32 33 func YesOrNo(question string) bool { 34 reader := bufio.NewReader(os.Stdin) 35 defer fmt.Println() 36 for { 37 fmt.Print(question + " (y/n) ") //nolint:forbidigo 38 39 answer, err := reader.ReadString('\n') 40 if err != nil { 41 panic(fmt.Errorf("couldn't read input: %w", err)) 42 } 43 44 answer = strings.ToLower(strings.Trim(answer, " \r\n\t")) 45 46 switch answer { 47 case "yes", "y": 48 return true 49 case "no", "n": 50 return false 51 default: 52 fmt.Printf("invalid answer %q, expect \"yes\" or \"no\"\n", answer) //nolint:forbidigo 53 } 54 } 55 }