-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzfs.go
44 lines (33 loc) · 755 Bytes
/
zfs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package zfs
import "github.com/theairkit/runcmd"
type Zfs struct {
*ZfsRunner
}
type ZfsRunner struct {
runcmd.Runner
sudo bool
}
var std = mustCreateRunner(NewZfsLocal(false))
func (z ZfsRunner) Command(name string, args ...string) runcmd.CmdWorker {
if z.sudo {
args = append([]string{name}, args...)
name = "sudo"
}
return z.Runner.Command(name, args...)
}
func NewZfsLocal(sudo bool) (Zfs, error) {
runner, err := runcmd.NewLocalRunner()
return Zfs{&ZfsRunner{runner, sudo}}, err
}
func NewZfs(runner runcmd.Runner, sudo bool) Zfs {
return Zfs{&ZfsRunner{runner, sudo}}
}
func SetStdSudo(sudo bool) {
std.sudo = sudo
}
func mustCreateRunner(operator Zfs, err error) *Zfs {
if err != nil {
panic(err)
}
return &operator
}