-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmds.go
90 lines (81 loc) · 1.91 KB
/
cmds.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package shell
import (
"os"
"os/exec"
)
type CmdProps struct {
Dir string
Verbose bool
}
type client struct {
cmd func(...string) error
cmdInPath func(string, ...string) error
dir string
}
func execute(cmd *exec.Cmd, dir string, verbose bool) error {
cmd.Dir = dir
if verbose {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
return cmd.Run()
}
func NewNpmCmd(cp CmdProps) NpmCmds {
return &client{
cmd: func(cmds ...string) error {
cmd := switchNodeCmd(cmds...)
cmd.Env = os.Environ()
return execute(cmd, cp.Dir, cp.Verbose)
},
cmdInPath: func(path string, cmds ...string) error {
cmd := switchNodeCmd(cmds...)
return execute(cmd, path, cp.Verbose)
},
dir: cp.Dir,
}
}
func NewGitCmd(cp CmdProps) GitCmds {
return &client{
cmd: func(cmds ...string) error {
cmd := exec.Command("git", cmds...)
return execute(cmd, cp.Dir, cp.Verbose)
},
cmdInPath: func(path string, cmds ...string) error {
cmd := exec.Command("git", cmds...)
return execute(cmd, path, cp.Verbose)
},
dir: cp.Dir,
}
}
func NewBundlerCmd(cp CmdProps) BundlerCmds {
return &client{
cmd: func(cmds ...string) error {
cmd := exec.Command("bundle", cmds...)
return execute(cmd, cp.Dir, cp.Verbose)
},
cmdInPath: func(path string, cmds ...string) error {
cmd := exec.Command("bundle", cmds...)
return execute(cmd, path, cp.Verbose)
},
dir: cp.Dir,
}
}
func NewRakeCmd(cp CmdProps) RakeCmds {
return &client{
cmd: func(cmds ...string) error {
cmd := exec.Command("rake", cmds...)
return execute(cmd, cp.Dir, cp.Verbose)
},
cmdInPath: func(path string, cmds ...string) error {
cmd := exec.Command("rake", cmds...)
return execute(cmd, path, cp.Verbose)
},
dir: cp.Dir,
}
}
// common commands
// Install is used by npm and bundler
func (c *client) Install(args ...string) error {
install := append([]string{"install"}, args...)
return c.cmd(install...)
}