chore: move general task functions to a new folder
This commit is contained in:
		
							parent
							
								
									4940258365
								
							
						
					
					
						commit
						c9e3696ffd
					
				@ -1,4 +1,4 @@
 | 
				
			|||||||
package tasks
 | 
					package common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "errors"
 | 
					import "errors"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -13,6 +13,9 @@ func (task *ExitTask) Execute() error {
 | 
				
			|||||||
	return errors.New("exit")
 | 
						return errors.New("exit")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (task *ExitTask) SetParentTaskers(tasks []Tasker) {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (task *ExitTask) String() string {
 | 
					func (task *ExitTask) String() string {
 | 
				
			||||||
	return "Exit"
 | 
						return "Exit"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										28
									
								
								go/tasks/common/general_task.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								go/tasks/common/general_task.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					package common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"ocl/portainer-devtool/configs"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GeneralTask struct {
 | 
				
			||||||
 | 
						Config      *configs.Config
 | 
				
			||||||
 | 
						ParentTasks []Tasker
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewGeneralTask(cfg *configs.Config) *GeneralTask {
 | 
				
			||||||
 | 
						return &GeneralTask{
 | 
				
			||||||
 | 
							Config: cfg,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (task *GeneralTask) Execute() error {
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (task *GeneralTask) SetParentTaskers(tasks []Tasker) {
 | 
				
			||||||
 | 
						task.ParentTasks = tasks
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (task *GeneralTask) String() string {
 | 
				
			||||||
 | 
						return ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										22
									
								
								go/tasks/common/return.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								go/tasks/common/return.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					package common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ReturnTask struct {
 | 
				
			||||||
 | 
						ParentTasks []Tasker
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func NewReturnTask(tasks []Tasker) *ReturnTask {
 | 
				
			||||||
 | 
						return &ReturnTask{
 | 
				
			||||||
 | 
							ParentTasks: tasks,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (task *ReturnTask) Execute() error {
 | 
				
			||||||
 | 
						return ListCommandMenu(task.ParentTasks, "", false, nil)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (task *ReturnTask) SetParentTaskers(tasks []Tasker) {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (task *ReturnTask) String() string {
 | 
				
			||||||
 | 
						return "Go Back"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,4 +1,4 @@
 | 
				
			|||||||
package tasks
 | 
					package common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
@ -10,11 +10,17 @@ import (
 | 
				
			|||||||
type Tasker interface {
 | 
					type Tasker interface {
 | 
				
			||||||
	Execute() error
 | 
						Execute() error
 | 
				
			||||||
	String() string
 | 
						String() string
 | 
				
			||||||
 | 
						SetParentTaskers(tasks []Tasker)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ListCommandMenu iterates task items to display them // on the screen as the menu options
 | 
					// ListCommandMenu iterates task items to display them // on the screen as the menu options
 | 
				
			||||||
func ListCommandMenu(taskItems []Tasker, menuDesp string) error {
 | 
					func ListCommandMenu(taskItems []Tasker, menuDesp string, rootMenu bool, parentTaskItems []Tasker) error {
 | 
				
			||||||
	taskItems = append(taskItems, NewExitTask())
 | 
						if rootMenu {
 | 
				
			||||||
 | 
							taskItems = append(taskItems, NewExitTask())
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							taskItems = append(taskItems, NewReturnTask(parentTaskItems))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		printMainMenu := func() {
 | 
							printMainMenu := func() {
 | 
				
			||||||
			taskNames := []string{}
 | 
								taskNames := []string{}
 | 
				
			||||||
@ -33,7 +39,6 @@ func ListCommandMenu(taskItems []Tasker, menuDesp string) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		option := utils.SelectMenuItem(printMainMenu)
 | 
							option := utils.SelectMenuItem(printMainMenu)
 | 
				
			||||||
 | 
					 | 
				
			||||||
		index, err := strconv.Atoi(option)
 | 
							index, err := strconv.Atoi(option)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			utils.ErrorPrint("please type the option number\n")
 | 
								utils.ErrorPrint("please type the option number\n")
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user