github.com/emmahsax/go-git-helper@v0.0.8-0.20240519163017-907b9de0fa52/internal/commandline/commandline.go (about) 1 package commandline 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/pterm/pterm" 8 ) 9 10 var AskMultipleChoice = func(question string, choices []string) string { 11 selectedOption, _ := pterm.DefaultInteractiveSelect. 12 WithDefaultText(question). 13 WithOnInterruptFunc(func() { 14 os.Exit(1) 15 }). 16 WithOptions(choices). 17 Show() 18 19 return selectedOption 20 } 21 22 var AskOpenEndedQuestion = func(question string, secret bool) string { 23 var result string 24 for { 25 if secret { 26 result, _ = pterm.DefaultInteractiveTextInput. 27 WithMultiLine(false). 28 WithDefaultText(question). 29 WithMask("*"). 30 WithOnInterruptFunc(func() { 31 os.Exit(1) 32 }). 33 Show() 34 } else { 35 result, _ = pterm.DefaultInteractiveTextInput. 36 WithMultiLine(false). 37 WithDefaultText(question). 38 WithOnInterruptFunc(func() { 39 os.Exit(1) 40 }). 41 Show() 42 } 43 44 if result != "" { 45 break 46 } 47 48 fmt.Println("--- This question is required ---") 49 } 50 51 return result 52 } 53 54 var AskYesNoQuestion = func(question string) bool { 55 result, _ := pterm.DefaultInteractiveConfirm. 56 WithDefaultText(question). 57 WithDefaultValue(true). 58 WithOnInterruptFunc(func() { 59 os.Exit(1) 60 }). 61 Show() 62 63 return result 64 }