github.com/swiftstack/proxyfs@v0.0.0-20201223034610-5434d919416e/pfsagentConfig/menu.go (about) 1 package pfsagentConfig 2 3 import ( 4 "fmt" 5 ) 6 7 func nextMenu(menuText string, menuOptions []string, menuOptionsTexts map[string]string) (userResponse string, err error) { 8 fmt.Println(menuText) 9 for { 10 displayOptions(menuOptions, menuOptionsTexts) 11 userResponse, err = getUserInput() 12 // fmt.Printf("raw response: %v\n", response) 13 if nil != err { 14 fmt.Println("Error retrieving user input", err) 15 continue 16 } 17 if len(userResponse) != 1 { 18 fmt.Printf("Input should be a single character. You entered %v. Please try again\n", userResponse) 19 continue 20 } 21 for _, validInput := range menuOptions { 22 if validInput == userResponse { 23 return menuOptionsTexts[userResponse], nil 24 } 25 26 } 27 fmt.Printf("Your input is not valid: '%v'. Options are: %v. Please try again\n\n", userResponse, menuOptions) 28 } 29 // return "", fmt.Errorf("Something went wrong trying to read user input") 30 } 31 32 func displayOptions(optionsList []string, optionsTextsMap map[string]string) { 33 for _, option := range optionsList { 34 fmt.Printf("%v:\t%v\n", option, optionsTextsMap[option]) 35 } 36 fmt.Printf("\nYour Selection: ") 37 }