Compare commits
	
		
			3 Commits
		
	
	
		
			8028a50cc3
			...
			b24dcfa9d9
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| b24dcfa9d9 | |||
| 5a6cd4ac16 | |||
| 4a5b954ad6 | 
							
								
								
									
										15
									
								
								go/commands/yarn.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								go/commands/yarn.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
package commands
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"ocl/portainer-devtool/utils"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// RunClient starts the portainer client
 | 
			
		||||
func RunPortainerClient(workdir string) error {
 | 
			
		||||
	err := utils.RunCommandWithStdoutPipe(workdir, "yarn")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return utils.RunCommandWithStdoutPipe(workdir, "yarn", "start:client")
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								go/main.go
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								go/main.go
									
									
									
									
									
								
							@ -1,10 +1,10 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"ocl/portainer-devtool/repositories"
 | 
			
		||||
	"ocl/portainer-devtool/utils"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
@ -12,18 +12,24 @@ const (
 | 
			
		||||
	MENU_OPTION_CE_REPO
 | 
			
		||||
	MENU_OPTION_AGENT_REPO
 | 
			
		||||
	MENU_OPTION_OTHERS
 | 
			
		||||
	MENU_OPTION_QUIT
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
 | 
			
		||||
	utils.MenuPrint()
 | 
			
		||||
	for {
 | 
			
		||||
 | 
			
		||||
	var option int
 | 
			
		||||
	_, err := fmt.Scanf("%d", &option)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
		printMainMenu := func() {
 | 
			
		||||
			utils.MenuPrint("Which repository or action do you want to operate:", `
 | 
			
		||||
 1. Portainer EE Repository
 | 
			
		||||
 2. Portainer CE Repository
 | 
			
		||||
 3. Portainer Agent Repository
 | 
			
		||||
 4. Others
 | 
			
		||||
 5. Quit`)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		option := utils.PromptMenu(printMainMenu)
 | 
			
		||||
 | 
			
		||||
		var action repositories.Actioner
 | 
			
		||||
		switch option {
 | 
			
		||||
		case MENU_OPTION_EE_REPO:
 | 
			
		||||
@ -34,7 +40,14 @@ func main() {
 | 
			
		||||
 | 
			
		||||
		case MENU_OPTION_OTHERS:
 | 
			
		||||
 | 
			
		||||
		case MENU_OPTION_QUIT:
 | 
			
		||||
			os.Exit(0)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		err := action.Execute()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Fatalln(err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.Fatal(action.Execute())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,18 @@ import (
 | 
			
		||||
	"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
 | 
			
		||||
@ -33,5 +45,27 @@ func (repo *PortainerEE) Execute() error {
 | 
			
		||||
		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`)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										45
									
								
								go/utils/command.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								go/utils/command.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,45 @@
 | 
			
		||||
package utils
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bufio"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func RunCommandWithStdoutPipe(workdir, progName string, args ...string) error {
 | 
			
		||||
	cmd := exec.Command(progName, args...)
 | 
			
		||||
	cmd.Dir = workdir
 | 
			
		||||
	out, err := cmd.StdoutPipe()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	scanner := bufio.NewScanner(out)
 | 
			
		||||
	go func() {
 | 
			
		||||
		counter := 0
 | 
			
		||||
		for scanner.Scan() {
 | 
			
		||||
			if counter > 10 {
 | 
			
		||||
				// Swallow the output
 | 
			
		||||
				if counter%50 == 0 {
 | 
			
		||||
					fmt.Printf("output %d lines in total.\n", counter)
 | 
			
		||||
				}
 | 
			
		||||
				counter++
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			PrintOutput("", scanner.Bytes())
 | 
			
		||||
			counter++
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	err = cmd.Start()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = cmd.Wait()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
@ -41,8 +41,10 @@ func InputPrint(message string) {
 | 
			
		||||
	fmt.Println(colorYellow, message, colorReset)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func MenuPrint() {
 | 
			
		||||
	InputPrint("Which repository or action do you want to operate:")
 | 
			
		||||
func MenuPrint(question, menu string) {
 | 
			
		||||
	if question != "" {
 | 
			
		||||
		InputPrint(fmt.Sprintf("[%s]", question))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 	menu := `
 | 
			
		||||
	// 1. Build Portainer EE/CE All
 | 
			
		||||
@ -56,10 +58,5 @@ func MenuPrint() {
 | 
			
		||||
	// 9. Cleanup Temporary Volume
 | 
			
		||||
	// 	`
 | 
			
		||||
 | 
			
		||||
	menu := `1. Portainer EE Repository
 | 
			
		||||
 2. Portainer CE Repository
 | 
			
		||||
 3. Portainer Agent Repository
 | 
			
		||||
 4. Others`
 | 
			
		||||
 | 
			
		||||
	fmt.Println(colorCyan, menu, colorReset)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,14 @@ func PromptContinue() bool {
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func PromptMenu(listMenu func()) int {
 | 
			
		||||
	listMenu()
 | 
			
		||||
 | 
			
		||||
	var option int
 | 
			
		||||
	fmt.Scanf("%d", &option)
 | 
			
		||||
	return option
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func prompt(question string) string {
 | 
			
		||||
	fmt.Printf("%s %s :%s", colorYellow, question, colorReset)
 | 
			
		||||
	var ret string
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user