From f51d0db7200ee372d6929c5fbf77db2c37dab32e Mon Sep 17 00:00:00 2001 From: Radu Topala Date: Wed, 26 May 2021 20:29:47 +0300 Subject: [PATCH] added cmd exec dir --- exec.go | 3 +++ task.go | 1 + utils.go | 12 +++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/exec.go b/exec.go index ab6554e..7ac1b1a 100644 --- a/exec.go +++ b/exec.go @@ -301,6 +301,9 @@ func (e *Exec) Local(command string, args ...interface{}) (o Output) { color.Green("[%s] %s %s", "local", ">", color.WhiteString("`%s`", command)) cmd := exec.Command("/bin/sh", "-c", command) + if e.TaskContext != nil && e.TaskContext.Dir != "" { + cmd.Dir = e.TaskContext.Dir + } stdout, err := cmd.StdoutPipe() if err != nil { diff --git a/task.go b/task.go index a85ab22..3e400c1 100644 --- a/task.go +++ b/task.go @@ -18,6 +18,7 @@ type task struct { Name string Options map[string]*Option Arguments map[string]*Argument + Dir string exec *Exec run taskFunction diff --git a/utils.go b/utils.go index c616357..927f737 100644 --- a/utils.go +++ b/utils.go @@ -17,9 +17,15 @@ import ( // Cd is a remote helper function that runs a `cd` before a command func (e *Exec) Cd(path string) { - command := "cd " + e.Parse(path) - color.Green("[%s] %s %s", e.ServerContext.Name, color.GreenString(">"), command) - e.ServerContext.sshClient.env = command + "; " + dir := e.Parse(path) + if e.TaskContext != nil { + e.TaskContext.Dir = dir + } + if e.ServerContext != nil { + command := "cd " + dir + color.Green("[%s] %s %s", e.ServerContext.Name, color.GreenString(">"), command) + e.ServerContext.sshClient.env = command + "; " + } } // CommandExist checks if a remote command exists on server