go(action): add the tool skeleton

This commit is contained in:
oscar 2022-08-21 17:05:29 +12:00
parent 10544e1c2d
commit 8028a50cc3
4 changed files with 85 additions and 0 deletions

3
go/go.mod Normal file
View File

@ -0,0 +1,3 @@
module ocl/portainer-devtool
go 1.18

40
go/main.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"fmt"
"log"
"ocl/portainer-devtool/repositories"
"ocl/portainer-devtool/utils"
)
const (
MENU_OPTION_EE_REPO int = iota + 1
MENU_OPTION_CE_REPO
MENU_OPTION_AGENT_REPO
MENU_OPTION_OTHERS
)
func main() {
utils.MenuPrint()
var option int
_, err := fmt.Scanf("%d", &option)
if err != nil {
log.Fatal(err)
}
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:
}
log.Fatal(action.Execute())
}

View File

@ -0,0 +1,5 @@
package repositories
type Actioner interface {
Execute() error
}

37
go/repositories/ee.go Normal file
View File

@ -0,0 +1,37 @@
package repositories
import (
"fmt"
"ocl/portainer-devtool/commands"
"ocl/portainer-devtool/utils"
)
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
}
return nil
}