interfaces.go 765 B

12345678910111213141516171819202122232425262728293031
  1. package executor
  2. import "os/exec"
  3. // CommandExecutor executes commands with os/exec
  4. type CommandExecutor interface {
  5. RunSync(string, ...string) ([]byte, error)
  6. }
  7. // ProcessRunner starts process and stops it
  8. type ProcessRunner interface {
  9. StartAsync(string, ...string) (*exec.Cmd, error)
  10. }
  11. // ProcessStopper stops exec.Cmd process
  12. type ProcessStopper interface {
  13. StopAsync(*exec.Cmd) error
  14. }
  15. func RunSync(executor CommandExecutor, command string, args ...string) ([]byte, error) {
  16. return executor.RunSync(command, args...)
  17. }
  18. func RunAsync(runner ProcessRunner, command string, args ...string) (*exec.Cmd, error) {
  19. return runner.StartAsync(command, args...)
  20. }
  21. func StopAsync(stopper ProcessStopper, prc *exec.Cmd) error {
  22. return stopper.StopAsync(prc)
  23. }