diff --git a/go/commands/yarn.go b/go/commands/yarn.go new file mode 100644 index 0000000..e6dd9f6 --- /dev/null +++ b/go/commands/yarn.go @@ -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") +} diff --git a/go/utils/command.go b/go/utils/command.go new file mode 100644 index 0000000..82cd379 --- /dev/null +++ b/go/utils/command.go @@ -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 +}