package executor

import "os/exec"

// CommandExecutor executes commands with os/exec
type CommandExecutor interface {
	RunSync(string, ...string) ([]byte, error)
}

// ProcessRunner starts process and stops it
type ProcessRunner interface {
	StartAsync(string, ...string) (*exec.Cmd, error)
}

// ProcessStopper stops exec.Cmd process
type ProcessStopper interface {
	StopAsync(*exec.Cmd) error
}

func RunSync(executor CommandExecutor, command string, args ...string) ([]byte, error) {
	return executor.RunSync(command, args...)
}

func RunAsync(runner ProcessRunner, command string, args ...string) (*exec.Cmd, error) {
	return runner.StartAsync(command, args...)
}

func StopAsync(stopper ProcessStopper, prc *exec.Cmd) error {
	return stopper.StopAsync(prc)
}
