Create Golang version devtool #7
43
go/main.go
43
go/main.go
@ -4,12 +4,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"ocl/portainer-devtool/configs"
|
"ocl/portainer-devtool/configs"
|
||||||
"ocl/portainer-devtool/tasks"
|
"ocl/portainer-devtool/tasks"
|
||||||
"ocl/portainer-devtool/utils"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
config, err := configs.GetConfig()
|
config, err := configs.GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
@ -18,50 +15,14 @@ func main() {
|
|||||||
config.Summarize()
|
config.Summarize()
|
||||||
|
|
||||||
// Init tasks
|
// Init tasks
|
||||||
|
|
||||||
taskItems := []tasks.Tasker{
|
taskItems := []tasks.Tasker{
|
||||||
tasks.NewGenerateJwtTokenTask(config),
|
tasks.NewGenerateJwtTokenTask(config),
|
||||||
tasks.NewCurlLookupTask(),
|
tasks.NewCurlLookupTask(),
|
||||||
tasks.NewCodeSecurityScanTask(),
|
tasks.NewCodeSecurityScanTask(),
|
||||||
|
tasks.NewListDevToolCommandTask(config),
|
||||||
|
|
||||||
tasks.NewExitTask(),
|
tasks.NewExitTask(),
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
tasks.ListCommandMenu(taskItems, "Which repository of action do you want operate:")
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,53 @@
|
|||||||
package tasks
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"ocl/portainer-devtool/utils"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
type Tasker interface {
|
type Tasker interface {
|
||||||
Execute() error
|
Execute() error
|
||||||
String() string
|
String() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListCommandMenu iterates task items to display them // on the screen as the menu options
|
||||||
|
func ListCommandMenu(taskItems []Tasker, menuDesp string) error {
|
||||||
|
for {
|
||||||
|
printMainMenu := func() {
|
||||||
|
taskNames := []string{}
|
||||||
|
for _, task := range taskItems {
|
||||||
|
taskNames = append(taskNames, task.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.PrintMenu(menuDesp, 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 {
|
||||||
|
utils.ErrorPrint("please type the option number\n")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if index < 1 || index > len(taskItems) {
|
||||||
|
utils.ErrorPrint(fmt.Sprintf("no such option %s, please select again\n", option))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = taskItems[index-1].Execute()
|
||||||
|
if err != nil {
|
||||||
|
utils.ErrorPrint(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user