rename DokkuCmd to ShellCmd and use strings.Join instead of fmt.Sprintf

This commit is contained in:
Michael Hobbs
2017-01-17 11:12:38 -08:00
parent 177b45c49b
commit f0efdd2ed4
3 changed files with 9 additions and 9 deletions

View File

@@ -10,8 +10,8 @@ import (
sh "github.com/codeskyblue/go-sh"
)
// DokkuCmd represents a shell command to be run for dokku
type DokkuCmd struct {
// ShellCmd represents a shell command to be run for dokku
type ShellCmd struct {
Env map[string]string
Command *exec.Cmd
CommandString string
@@ -19,12 +19,12 @@ type DokkuCmd struct {
ShowOutput bool
}
// NewDokkuCmd creates a new DokkuCmd
func NewDokkuCmd(command string) *DokkuCmd {
// NewShellCmd returns a new ShellCmd struct
func NewShellCmd(command string) *ShellCmd {
items := strings.Split(command, " ")
cmd := items[0]
args := items[1:]
return &DokkuCmd{
return &ShellCmd{
Command: exec.Command(cmd, args...),
CommandString: command,
Args: args,
@@ -33,7 +33,7 @@ func NewDokkuCmd(command string) *DokkuCmd {
}
// Execute is a lightweight wrapper around exec.Command
func (dc *DokkuCmd) Execute() bool {
func (dc *ShellCmd) Execute() bool {
env := os.Environ()
for k, v := range dc.Env {
env = append(env, fmt.Sprintf("%s=%s", k, v))
@@ -132,7 +132,7 @@ func GetAppImageRepo(appName string) string {
// VerifyImage returns true if docker image exists in local repo
func VerifyImage(image string) bool {
imageCmd := NewDokkuCmd(fmt.Sprintf("docker inspect %s", image))
imageCmd := NewShellCmd(strings.Join([]string{"docker inspect", image}, " "))
imageCmd.ShowOutput = false
if imageCmd.Execute() {
return true

View File

@@ -23,7 +23,7 @@ func main() {
cmdEnv := map[string]string{
"GIT_DIR": appRoot,
}
gitGcCmd := common.NewDokkuCmd("git gc --aggressive")
gitGcCmd := common.NewShellCmd("git gc --aggressive")
gitGcCmd.Env = cmdEnv
gitGcCmd.Execute()
}

View File

@@ -24,7 +24,7 @@ func main() {
dokkuGlobalRunArgs := common.MustGetEnv("DOKKU_GLOBAL_RUN_ARGS")
image := common.GetDeployingAppImageName(appName, "", "")
if info, _ := os.Stat(cacheDir); info != nil && info.IsDir() {
purgeCacheCmd := common.NewDokkuCmd(strings.Join([]string{"docker run --rm", dokkuGlobalRunArgs,
purgeCacheCmd := common.NewShellCmd(strings.Join([]string{"docker run --rm", dokkuGlobalRunArgs,
"-v", strings.Join([]string{cacheDir, ":/cache"}, ""), image,
`find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} ;`}, " "))
purgeCacheCmd.Execute()