Compare commits
No commits in common. "dfbd70b3266c962e7e1ea781e99f6a59fc9f7b16" and "f4f3164978d2c72885291d3e063966cb251603d4" have entirely different histories.
dfbd70b326
...
f4f3164978
10
go/main.go
10
go/main.go
@ -4,7 +4,6 @@ import (
|
||||
"log"
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -16,17 +15,12 @@ func main() {
|
||||
config.Summarize()
|
||||
|
||||
// Init tasks
|
||||
taskItems := []common.Tasker{
|
||||
tasks.NewListRepositoriesTask(config),
|
||||
taskItems := []tasks.Tasker{
|
||||
tasks.NewGenerateJwtTokenTask(config),
|
||||
tasks.NewCurlLookupTask(),
|
||||
tasks.NewCodeSecurityScanTask(),
|
||||
tasks.NewListDevToolCommandTask(config),
|
||||
}
|
||||
|
||||
for _, taskItem := range taskItems {
|
||||
taskItem.SetParentTaskers(taskItems)
|
||||
}
|
||||
|
||||
common.ListCommandMenu(taskItems, "Which repository of action do you want to operate:", true, nil)
|
||||
tasks.ListCommandMenu(taskItems, "Which repository of action do you want operate:")
|
||||
}
|
||||
|
5
go/repositories/actioner.go
Normal file
5
go/repositories/actioner.go
Normal file
@ -0,0 +1,5 @@
|
||||
package repositories
|
||||
|
||||
type Actioner interface {
|
||||
Execute() error
|
||||
}
|
71
go/repositories/ee.go
Normal file
71
go/repositories/ee.go
Normal file
@ -0,0 +1,71 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ocl/portainer-devtool/commands"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
ACTION_EE_BUILD_ALL int = iota + 1
|
||||
ACTION_EE_RUN_FRONTEND
|
||||
ACTION_EE_RUN_BACKEND
|
||||
ACTION_EE_VALIDATE_ALL
|
||||
ACTION_EE_VALIDATE_FRONTEND
|
||||
ACTION_EE_VALIDATE_BACKEND
|
||||
ACTION_EE_RUN_UNIT_TEST_ALL
|
||||
ACTION_EE_RUN_UNIT_TEST_FRONTEND
|
||||
ACTION_EE_RUN_UNIT_TEST_BACKEND
|
||||
)
|
||||
|
||||
type PortainerEE struct {
|
||||
WorkDir string
|
||||
FrontendDir string
|
||||
BackendDir string
|
||||
}
|
||||
|
||||
func NewPortainerEERepository() *PortainerEE {
|
||||
repo := &PortainerEE{
|
||||
WorkDir: "/home/oscarzhou/source/github.com/portainer/portainer-ee",
|
||||
}
|
||||
|
||||
utils.HighlightPrint("Your portainer EE repository work directory is ")
|
||||
fmt.Println(repo.WorkDir)
|
||||
|
||||
return repo
|
||||
}
|
||||
|
||||
func (repo *PortainerEE) Execute() error {
|
||||
err := commands.ListBranches(repo.WorkDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !utils.PromptContinue() {
|
||||
return nil
|
||||
}
|
||||
|
||||
option := utils.PromptMenu(repo.listSubMenu)
|
||||
switch option {
|
||||
case ACTION_EE_BUILD_ALL:
|
||||
|
||||
case ACTION_EE_RUN_FRONTEND:
|
||||
commands.RunPortainerClient(repo.WorkDir)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *PortainerEE) listSubMenu() {
|
||||
utils.MenuPrint("Do you want?", `
|
||||
1. Build both front-end and backend
|
||||
2. Run front-end only
|
||||
3. Run backend only
|
||||
4. Validate both fornt-end and backend before commit
|
||||
5. Validate front-end only before commit
|
||||
6. Validate backend only before commit
|
||||
7. Run unit tests for both front-end and backend
|
||||
8. Run unit tests for front-end only
|
||||
9. Run unit tests for backend only`)
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package unpacker
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type BuildDockerImageSubTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewBuildDockerImageSubTask(cfg *configs.Config) *BuildDockerImageSubTask {
|
||||
return &BuildDockerImageSubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *BuildDockerImageSubTask) Execute() error {
|
||||
utils.SuccessPrint(`
|
||||
docker image tag docker.io/portainer/compose-unpacker:latest oscarzhou/compose-unpacker:28
|
||||
docker image push oscarzhou/compose-unpacker:28
|
||||
`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *BuildDockerImageSubTask) String() string {
|
||||
return "Build Docker Image"
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type CodeSecurityScanTask struct {
|
||||
ParentTasks []common.Tasker
|
||||
}
|
||||
|
||||
func NewCodeSecurityScanTask() *CodeSecurityScanTask {
|
||||
@ -32,10 +30,6 @@ func (task *CodeSecurityScanTask) Execute() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *CodeSecurityScanTask) SetParentTaskers(tasks []common.Tasker) {
|
||||
task.ParentTasks = tasks
|
||||
}
|
||||
|
||||
func (task *CodeSecurityScanTask) String() string {
|
||||
return "Code Security Scan"
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
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 ""
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
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"
|
||||
}
|
@ -2,12 +2,10 @@ package tasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type CurlLookupTask struct {
|
||||
ParentTasks []common.Tasker
|
||||
}
|
||||
|
||||
func NewCurlLookupTask() *CurlLookupTask {
|
||||
@ -45,10 +43,6 @@ func (task *CurlLookupTask) Execute() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *CurlLookupTask) SetParentTaskers(tasks []common.Tasker) {
|
||||
task.ParentTasks = tasks
|
||||
}
|
||||
|
||||
func (task *CurlLookupTask) String() string {
|
||||
return "Lookup Curl Commands"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package common
|
||||
package tasks
|
||||
|
||||
import "errors"
|
||||
|
||||
@ -13,9 +13,6 @@ func (task *ExitTask) Execute() error {
|
||||
return errors.New("exit")
|
||||
}
|
||||
|
||||
func (task *ExitTask) SetParentTaskers(tasks []Tasker) {
|
||||
}
|
||||
|
||||
func (task *ExitTask) String() string {
|
||||
return "Exit"
|
||||
}
|
@ -7,11 +7,10 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
type GenerateJwtTokenTask struct {
|
||||
common.GeneralTask
|
||||
Config *configs.Config
|
||||
}
|
||||
|
||||
type GenerateJwtTokenResponse struct {
|
||||
@ -20,7 +19,7 @@ type GenerateJwtTokenResponse struct {
|
||||
|
||||
func NewGenerateJwtTokenTask(cfg *configs.Config) *GenerateJwtTokenTask {
|
||||
return &GenerateJwtTokenTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
Config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,32 +2,26 @@ package tasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/tasks/subtasks"
|
||||
)
|
||||
|
||||
type ListDevToolCommandTask struct {
|
||||
common.GeneralTask
|
||||
Config *configs.Config
|
||||
}
|
||||
|
||||
func NewListDevToolCommandTask(cfg *configs.Config) *ListDevToolCommandTask {
|
||||
return &ListDevToolCommandTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
Config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
func (task *ListDevToolCommandTask) Execute() error {
|
||||
subTaskItems := []common.Tasker{
|
||||
subTaskItems := []Tasker{
|
||||
subtasks.NewListVolumeSubTask(task.Config),
|
||||
subtasks.NewListRepositorySubTask(task.Config),
|
||||
}
|
||||
|
||||
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)
|
||||
ListCommandMenu(subTaskItems, "Which management commands do you want to choose:")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
@ -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"
|
||||
}
|
@ -2,18 +2,17 @@ package subtasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ListRepositorySubTask struct {
|
||||
common.GeneralTask
|
||||
Config *configs.Config
|
||||
}
|
||||
|
||||
func NewListRepositorySubTask(cfg *configs.Config) *ListRepositorySubTask {
|
||||
return &ListRepositorySubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
Config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,19 +4,18 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ListVolumeSubTask struct {
|
||||
common.GeneralTask
|
||||
Config *configs.Config
|
||||
}
|
||||
|
||||
func NewListVolumeSubTask(cfg *configs.Config) *ListVolumeSubTask {
|
||||
return &ListVolumeSubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
Config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package common
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -10,17 +10,11 @@ import (
|
||||
type Tasker interface {
|
||||
Execute() error
|
||||
String() string
|
||||
SetParentTaskers(tasks []Tasker)
|
||||
}
|
||||
|
||||
// ListCommandMenu iterates task items to display them // on the screen as the menu options
|
||||
func ListCommandMenu(taskItems []Tasker, menuDesp string, rootMenu bool, parentTaskItems []Tasker) error {
|
||||
if rootMenu {
|
||||
func ListCommandMenu(taskItems []Tasker, menuDesp string) error {
|
||||
taskItems = append(taskItems, NewExitTask())
|
||||
} else {
|
||||
taskItems = append(taskItems, NewReturnTask(parentTaskItems))
|
||||
}
|
||||
|
||||
for {
|
||||
printMainMenu := func() {
|
||||
taskNames := []string{}
|
||||
@ -39,6 +33,7 @@ func ListCommandMenu(taskItems []Tasker, menuDesp string, rootMenu bool, parentT
|
||||
}
|
||||
|
||||
option := utils.SelectMenuItem(printMainMenu)
|
||||
|
||||
index, err := strconv.Atoi(option)
|
||||
if err != nil {
|
||||
utils.ErrorPrint("please type the option number\n")
|
Loading…
Reference in New Issue
Block a user