task: add tasks skeleton

This commit is contained in:
oscar 2022-09-21 17:42:47 +12:00
parent 2ab17147fb
commit 8463725b9c
5 changed files with 81 additions and 35 deletions

View File

@ -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() {
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`)
}
option := 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()
config, err := configs.GetConfig()
if err != nil {
log.Fatalln(err)
}
// Init tasks
taskItems := []tasks.Tasker{
tasks.NewGenerateJwtTokenTask(config),
}
for {
printMainMenu := func() {
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`)
}
utils.PromptMenu(printMainMenu)
}
}

16
go/tasks/build_all.go Normal file
View File

@ -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"
}

15
go/tasks/build_backend.go Normal file
View File

@ -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"
}

21
go/tasks/jwt_token_gen.go Normal file
View File

@ -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"
}

6
go/tasks/tasker.go Normal file
View File

@ -0,0 +1,6 @@
package tasks
type Tasker interface {
Execute() error
String() string
}