step.go 570 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "os/exec"
  4. )
  5. type step struct {
  6. name string
  7. exe string
  8. args []string
  9. message string
  10. proj string
  11. }
  12. func newStep(name, message, proj, exe string, args []string) step {
  13. return step{
  14. name: name,
  15. exe: exe,
  16. args: args,
  17. message: message,
  18. proj: proj,
  19. }
  20. }
  21. func (s step) execute() (string, error) {
  22. cmd := exec.Command(s.exe, s.args...)
  23. cmd.Dir = s.proj
  24. if err := cmd.Run(); err != nil {
  25. return "", &stepErr{
  26. step: s.name,
  27. msg: "failed to execute",
  28. cause: err,
  29. }
  30. }
  31. return s.message, nil
  32. }