Skip to content

Commit

Permalink
added cmd exec dir
Browse files Browse the repository at this point in the history
  • Loading branch information
radutopala committed May 26, 2021
1 parent f57c41d commit f51d0db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type task struct {
Name string
Options map[string]*Option
Arguments map[string]*Argument
Dir string

exec *Exec
run taskFunction
Expand Down
12 changes: 9 additions & 3 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f51d0db

Please sign in to comment.