task: add the task selection skeleton

pull/7/head
oscar 2022-09-22 13:58:21 +12:00
parent 423c0b5a37
commit d50bf24226
2 changed files with 18 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"ocl/portainer-devtool/configs" "ocl/portainer-devtool/configs"
"ocl/portainer-devtool/tasks" "ocl/portainer-devtool/tasks"
"ocl/portainer-devtool/utils" "ocl/portainer-devtool/utils"
"strconv"
) )
func main() { func main() {
@ -36,8 +37,23 @@ func main() {
// 5. Quit`) // 5. Quit`)
} }
utils.PromptMenu(printMainMenu) option := utils.SelectMenuItem(printMainMenu)
index, err := strconv.Atoi(option)
if err != nil {
log.Printf("please type the option number\n")
continue
}
if index < 1 || index > len(taskItems) {
log.Printf("no such option %s, please select again\n", option)
continue
}
err = taskItems[index-1].Execute()
if err != nil {
log.Fatalln(err)
}
} }
} }

View File

@ -23,7 +23,7 @@ func PromptConfirm(question string) bool {
return false return false
} }
func PromptMenu(listMenu func()) string { func SelectMenuItem(listMenu func()) string {
listMenu() listMenu()
var option string var option string