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.
33 lines
592 B
Go
33 lines
592 B
Go
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 "", &ShellError{strings.Join(cmd.Args, " "), err}
|
|
}
|
|
|
|
return strings.TrimSuffix(string(output), "\n"), nil
|
|
}
|
|
|
|
func (c DefaultCommander) ExecSilently(cmd *exec.Cmd) error {
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
return &ShellError{strings.Join(cmd.Args, " "), err}
|
|
}
|
|
return nil
|
|
}
|