You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
smug/commander.go

29 lines
463 B
Go

3 years ago
package main
import (
"os/exec"
"strings"
)
type Commander interface {
Exec(cmd *exec.Cmd) (string, error)
ExecSilently(cmd *exec.Cmd) error
}
type DefaultCommander struct {
}
func (c DefaultCommander) Exec(cmd *exec.Cmd) (string, error) {
output, err := cmd.CombinedOutput()
if err != nil {
return "", err
}
return strings.TrimSuffix(string(output), "\n"), nil
}
func (c DefaultCommander) ExecSilently(cmd *exec.Cmd) error {
return cmd.Run()
}