package cmd import ( "fmt" "os" "os/exec" "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") } lang := project.GetLanguage() 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() { projectCmd.AddCommand(projectRunCmd) }