portainer-devtool/go/main.go

67 lines
1.2 KiB
Go

package main
import (
"log"
"ocl/portainer-devtool/configs"
"ocl/portainer-devtool/tasks"
"ocl/portainer-devtool/utils"
"strconv"
)
func main() {
config, err := configs.GetConfig()
if err != nil {
log.Fatalln(err)
}
config.Summarize()
// Init tasks
taskItems := []tasks.Tasker{
tasks.NewGenerateJwtTokenTask(config),
tasks.NewCurlLookupTask(),
tasks.NewExitTask(),
}
for {
printMainMenu := func() {
taskNames := []string{}
for _, task := range taskItems {
taskNames = append(taskNames, task.String())
}
utils.PrintMenu("Which repository of action do you want operate:", taskNames)
// utils.MenuPrint("Which repository or action do you want to operate:", `
// 1. Portainer EE Repository
// 2. Portainer CE Repository
// 3. Portainer Agent Repository
// 4. Others
// 5. Quit`)
}
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)
}
}
}