| 259 | } |
| 260 | |
| 261 | func CallPluginExecutableInBackground(main string, argv []string, extraEnvVars map[string]string) error { |
| 262 | env := os.Environ() |
| 263 | for k, v := range extraEnvVars { |
| 264 | env = append(env, k+"="+v) |
| 265 | } |
| 266 | |
| 267 | stderrOut := &bytes.Buffer{} |
| 268 | prog := exec.Command(main, argv...) |
| 269 | prog.Env = env |
| 270 | prog.Stderr = stderrOut |
| 271 | if err := prog.Start(); err != nil { |
| 272 | if strings.Contains(err.Error(), "no such file or directory") { |
| 273 | return fmt.Errorf("the plugin's binary was not found (%v). Please reinstall the plugin and make sure there are no other conflicting plugins installed (run 'devspace list plugins' to see all installed plugins)", err) |
| 274 | } |
| 275 | |
| 276 | return err |
| 277 | } |
| 278 | |
| 279 | go func() { |
| 280 | err := prog.Wait() |
| 281 | if err != nil { |
| 282 | if eerr, ok := err.(*exec.ExitError); ok { |
| 283 | os.Stderr.Write([]byte(fmt.Sprintf("Plugin Hook %s failed (code: %d): %s", main+" "+strings.Join(argv, " "), eerr.ExitCode(), stderrOut.String()))) |
| 284 | } |
| 285 | } |
| 286 | }() |
| 287 | return nil |
| 288 | } |
| 289 | |
| 290 | // CallPluginExecutable is used to setup the environment for the plugin and then |
| 291 | // call the executable specified by the parameter 'main' |