Implement golang project run

This commit is contained in:
2023-12-29 13:35:56 -05:00
parent e1545d114b
commit 03e992bf6b
3 changed files with 58 additions and 12 deletions

View File

@@ -1,6 +1,10 @@
package cmd
import (
"fmt"
"os"
"os/exec"
"github.com/spf13/cobra"
)
@@ -18,11 +22,24 @@ func projectRunCmdRun(cmd *cobra.Command, args []string) {
plog.Fatal("No project selected, nothing to open")
}
plog.Info("Running Projet", plog.Args("lang", project.Language))
lang := project.GetLanguage()
if project.Language == nil {
if lang == nil {
plog.Fatal("GitLab isn't sure what language this project is... can't run.")
}
plog.Debug(fmt.Sprintf("Project is written in %s, %.2f%% coverage", lang.Name, lang.Percentage))
switch lang.Name {
case "Go":
cmdArgs := []string{"run", "."} // Run from cwd
cmdArgs = append(cmdArgs, args[1:]...) // Support flags from shell command
cmd := exec.CommandContext(cmd.Context(), "go", cmdArgs...) // Honor parent context
cmd.Env = os.Environ()
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
}
}
func init() {