restructure and include Makefile
This commit is contained in:
28
internal/runner/runner.go
Normal file
28
internal/runner/runner.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type Runner interface {
|
||||
Run(context.Context, string, ...any) ([]byte, error)
|
||||
}
|
||||
|
||||
type ZRunner struct {
|
||||
Prog string
|
||||
Args []string
|
||||
}
|
||||
|
||||
func (runner *ZRunner) Run(ctx context.Context, command string, formatArgs ...any) ([]byte, error) {
|
||||
var subArgs string
|
||||
if len(formatArgs) > 0 {
|
||||
subArgs = fmt.Sprintf(command, formatArgs...)
|
||||
} else {
|
||||
subArgs = command
|
||||
}
|
||||
args := append(runner.Args, subArgs)
|
||||
cmd := exec.Command(runner.Prog, args...)
|
||||
return cmd.CombinedOutput()
|
||||
}
|
||||
21
internal/runner/runner_test.go
Normal file
21
internal/runner/runner_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package cmd_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.gentoo.party/sam/thanks/internal/cmd"
|
||||
)
|
||||
|
||||
func Test_ZCommand(t *testing.T) {
|
||||
localRunner := &cmd.ZRunner{
|
||||
Prog: "/bin/sh",
|
||||
Args: []string{"-c"},
|
||||
}
|
||||
|
||||
zfsList := "zfs list %s"
|
||||
out, err := localRunner.Run(context.TODO(), zfsList, "zroot")
|
||||
if err != nil {
|
||||
t.Errorf("localRunner failed: %s\n\n%s", err.Error(), out)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user