refactor: support to list repository menu from command menu

oscar-next
oscarzhou 2023-01-09 12:04:27 +13:00
parent dfbd70b326
commit f7b2fcb5bd
3 changed files with 39 additions and 70 deletions

View File

@ -1,36 +0,0 @@
package tasks
import (
"ocl/portainer-devtool/configs"
"ocl/portainer-devtool/repositories/unpacker"
"ocl/portainer-devtool/tasks/common"
)
type ListRepoActionsSubTask struct {
Config *configs.Config
ParentTasks []common.Tasker
}
func NewListRepoActionsSubTask(cfg *configs.Config) *ListRepoActionsSubTask {
return &ListRepoActionsSubTask{
Config: cfg,
}
}
func (task *ListRepoActionsSubTask) Execute() error {
subTaskItems := []common.Tasker{
unpacker.NewBuildDockerImageSubTask(task.Config),
}
common.ListCommandMenu(subTaskItems, "Which management commands do you want to choose:", false, task.ParentTasks)
return nil
}
func (task *ListRepoActionsSubTask) SetParentTaskers(tasks []common.Tasker) {
task.ParentTasks = tasks
}
func (task *ListRepoActionsSubTask) String() string {
return "Choose Repository Commands"
}

View File

@ -0,0 +1,39 @@
package tasks
import (
"ocl/portainer-devtool/configs"
"ocl/portainer-devtool/repositories/agent"
portaineree "ocl/portainer-devtool/repositories/portainer-ee"
"ocl/portainer-devtool/repositories/unpacker"
"ocl/portainer-devtool/tasks/common"
)
type ListRepositoryMenuTask struct {
common.GeneralTask
}
func NewListRepositoryMenuTask(cfg *configs.Config) *ListRepositoryMenuTask {
return &ListRepositoryMenuTask{
GeneralTask: *common.NewGeneralTask(cfg),
}
}
func (task *ListRepositoryMenuTask) Execute() error {
subTaskItems := []common.Tasker{
portaineree.NewMenuSubTask(task.Config),
agent.NewMenuSubTask(task.Config),
unpacker.NewMenuSubTask(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 *ListRepositoryMenuTask) String() string {
return "Choose Repositories"
}

View File

@ -1,34 +0,0 @@
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"
}