Create Golang version devtool #7

Merged
oscar merged 25 commits from oscar-next into master 2022-12-29 20:34:22 +11:00
2 changed files with 60 additions and 0 deletions
Showing only changes of commit 4a5b954ad6 - Show all commits

15
go/commands/yarn.go Normal file
View 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")
}

45
go/utils/command.go Normal file
View 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
}