2023-12-29 15:24:12 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-12-29 18:35:56 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
2023-12-29 15:24:12 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var projectRunCmd = &cobra.Command{
|
|
|
|
Use: "run",
|
|
|
|
Short: "Run the project (e.g. go run .)",
|
|
|
|
Aliases: []string{"exec", "r"},
|
|
|
|
Long: projRunCmdLong,
|
|
|
|
Run: projectRunCmdRun,
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectRunCmdRun(cmd *cobra.Command, args []string) {
|
|
|
|
project := fzfCwdOrSearchProjectAliases(searchStringFromArgs(args))
|
|
|
|
if project == nil {
|
|
|
|
plog.Fatal("No project selected, nothing to open")
|
|
|
|
}
|
|
|
|
|
2023-12-29 18:35:56 +00:00
|
|
|
lang := project.GetLanguage()
|
2023-12-29 15:24:12 +00:00
|
|
|
|
2023-12-29 18:35:56 +00:00
|
|
|
if lang == nil {
|
2023-12-29 15:24:12 +00:00
|
|
|
plog.Fatal("GitLab isn't sure what language this project is... can't run.")
|
|
|
|
}
|
2023-12-29 18:35:56 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
2023-12-29 15:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
projectCmd.AddCommand(projectRunCmd)
|
|
|
|
}
|