From d50bf2422670ea7da87ca121e3e709f451913a7a Mon Sep 17 00:00:00 2001 From: oscar Date: Thu, 22 Sep 2022 13:58:21 +1200 Subject: [PATCH] task: add the task selection skeleton --- go/main.go | 18 +++++++++++++++++- go/utils/prompt.go | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/go/main.go b/go/main.go index 9389030..932f70f 100644 --- a/go/main.go +++ b/go/main.go @@ -5,6 +5,7 @@ import ( "ocl/portainer-devtool/configs" "ocl/portainer-devtool/tasks" "ocl/portainer-devtool/utils" + "strconv" ) func main() { @@ -36,8 +37,23 @@ func main() { // 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) + } } } diff --git a/go/utils/prompt.go b/go/utils/prompt.go index 827881e..9c7fabb 100644 --- a/go/utils/prompt.go +++ b/go/utils/prompt.go @@ -23,7 +23,7 @@ func PromptConfirm(question string) bool { return false } -func PromptMenu(listMenu func()) string { +func SelectMenuItem(listMenu func()) string { listMenu() var option string