From 8463725b9c88e62c9cedaed16167818e3654ab78 Mon Sep 17 00:00:00 2001 From: oscar Date: Wed, 21 Sep 2022 17:42:47 +1200 Subject: [PATCH] task: add tasks skeleton --- go/main.go | 58 ++++++++++++++++----------------------- go/tasks/build_all.go | 16 +++++++++++ go/tasks/build_backend.go | 15 ++++++++++ go/tasks/jwt_token_gen.go | 21 ++++++++++++++ go/tasks/tasker.go | 6 ++++ 5 files changed, 81 insertions(+), 35 deletions(-) create mode 100644 go/tasks/build_all.go create mode 100644 go/tasks/build_backend.go create mode 100644 go/tasks/jwt_token_gen.go create mode 100644 go/tasks/tasker.go diff --git a/go/main.go b/go/main.go index c6e9b43..45c851a 100644 --- a/go/main.go +++ b/go/main.go @@ -2,52 +2,40 @@ package main import ( "log" - "ocl/portainer-devtool/repositories" + "ocl/portainer-devtool/configs" + "ocl/portainer-devtool/tasks" "ocl/portainer-devtool/utils" - "os" -) - -const ( - MENU_OPTION_EE_REPO int = iota + 1 - MENU_OPTION_CE_REPO - MENU_OPTION_AGENT_REPO - MENU_OPTION_OTHERS - MENU_OPTION_QUIT ) func main() { + config, err := configs.GetConfig() + if err != nil { + log.Fatalln(err) + } + + // Init tasks + + taskItems := []tasks.Tasker{ + tasks.NewGenerateJwtTokenTask(config), + } + for { printMainMenu := func() { - 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`) + + utils.PrintMenu("Which repository of action do you want operate:", taskItems) + + // 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.PromptMenu(printMainMenu) + utils.PromptMenu(printMainMenu) - var action repositories.Actioner - switch option { - case MENU_OPTION_EE_REPO: - action = repositories.NewPortainerEERepository() - case MENU_OPTION_CE_REPO: - - case MENU_OPTION_AGENT_REPO: - - case MENU_OPTION_OTHERS: - - case MENU_OPTION_QUIT: - os.Exit(0) - } - - err := action.Execute() - if err != nil { - log.Fatalln(err) - } } } diff --git a/go/tasks/build_all.go b/go/tasks/build_all.go new file mode 100644 index 0000000..4f4208e --- /dev/null +++ b/go/tasks/build_all.go @@ -0,0 +1,16 @@ +package tasks + +import "ocl/portainer-devtool/configs" + +type BuildAllTask struct { + Config *configs.Config +} + +func (task *BuildAllTask) Execute() error { + + return nil +} + +func (task *BuildAllTask) String() string { + return "Build all" +} diff --git a/go/tasks/build_backend.go b/go/tasks/build_backend.go new file mode 100644 index 0000000..6644eb1 --- /dev/null +++ b/go/tasks/build_backend.go @@ -0,0 +1,15 @@ +package tasks + +import "ocl/portainer-devtool/configs" + +type BuildBackendOnlyTask struct { + Config *configs.Config +} + +func (task *BuildBackendOnlyTask) Execute() error { + return nil +} + +func (task *BuildBackendOnlyTask) String() string { + return "Build backend only" +} diff --git a/go/tasks/jwt_token_gen.go b/go/tasks/jwt_token_gen.go new file mode 100644 index 0000000..393764f --- /dev/null +++ b/go/tasks/jwt_token_gen.go @@ -0,0 +1,21 @@ +package tasks + +import "ocl/portainer-devtool/configs" + +type GenerateJwtTokenTask struct { + Config *configs.Config +} + +func NewGenerateJwtTokenTask(cfg *configs.Config) *GenerateJwtTokenTask { + return &GenerateJwtTokenTask{ + Config: cfg, + } +} + +func (task *GenerateJwtTokenTask) Execute() error { + return nil +} + +func (task *GenerateJwtTokenTask) String() string { + return "Generate JWT token" +} diff --git a/go/tasks/tasker.go b/go/tasks/tasker.go new file mode 100644 index 0000000..bc922dd --- /dev/null +++ b/go/tasks/tasker.go @@ -0,0 +1,6 @@ +package tasks + +type Tasker interface { + Execute() error + String() string +}