task: set parent task for multi layer tasks

This commit is contained in:
oscarzhou 2023-01-08 21:40:39 +13:00
parent 96cb2cc8a4
commit dfbd70b326
3 changed files with 52 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import (
"log"
"ocl/portainer-devtool/configs"
"ocl/portainer-devtool/tasks"
"ocl/portainer-devtool/tasks/common"
)
func main() {
@ -15,12 +16,17 @@ func main() {
config.Summarize()
// Init tasks
taskItems := []tasks.Tasker{
taskItems := []common.Tasker{
tasks.NewListRepositoriesTask(config),
tasks.NewGenerateJwtTokenTask(config),
tasks.NewCurlLookupTask(),
tasks.NewCodeSecurityScanTask(),
tasks.NewListDevToolCommandTask(config),
}
tasks.ListCommandMenu(taskItems, "Which repository of action do you want operate:")
for _, taskItem := range taskItems {
taskItem.SetParentTaskers(taskItems)
}
common.ListCommandMenu(taskItems, "Which repository of action do you want to operate:", true, nil)
}

View File

@ -2,26 +2,32 @@ package tasks
import (
"ocl/portainer-devtool/configs"
"ocl/portainer-devtool/tasks/common"
"ocl/portainer-devtool/tasks/subtasks"
)
type ListDevToolCommandTask struct {
Config *configs.Config
common.GeneralTask
}
func NewListDevToolCommandTask(cfg *configs.Config) *ListDevToolCommandTask {
return &ListDevToolCommandTask{
Config: cfg,
GeneralTask: *common.NewGeneralTask(cfg),
}
}
func (task *ListDevToolCommandTask) Execute() error {
subTaskItems := []Tasker{
subTaskItems := []common.Tasker{
subtasks.NewListVolumeSubTask(task.Config),
subtasks.NewListRepositorySubTask(task.Config),
}
ListCommandMenu(subTaskItems, "Which management commands do you want to choose:")
for _, taskItem := range subTaskItems {
taskItem.SetParentTaskers(subTaskItems)
}
// ListCommandMenu(subTaskItems, "Which management commands do you want to choose:")
common.ListCommandMenu(subTaskItems, "Which management commands do you want to choose:", false, task.ParentTasks)
return nil
}

34
go/tasks/list_repos.go Normal file
View File

@ -0,0 +1,34 @@
package tasks
import (
"ocl/portainer-devtool/configs"
"ocl/portainer-devtool/tasks/common"
)
type ListRepositoriesTask struct {
common.GeneralTask
}
func NewListRepositoriesTask(cfg *configs.Config) *ListRepositoriesTask {
return &ListRepositoriesTask{
GeneralTask: *common.NewGeneralTask(cfg),
}
}
func (task *ListRepositoriesTask) Execute() error {
subTaskItems := []common.Tasker{
NewListRepoActionsSubTask(task.Config),
}
for _, taskItem := range subTaskItems {
taskItem.SetParentTaskers(subTaskItems)
}
common.ListCommandMenu(subTaskItems, "Which management commands do you want to choose:", false, task.ParentTasks)
return nil
}
func (task *ListRepositoriesTask) String() string {
return "List All Repositories"
}