Skip to content

Commit f51d0db

Browse files
committed
added cmd exec dir
1 parent f57c41d commit f51d0db

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

exec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ func (e *Exec) Local(command string, args ...interface{}) (o Output) {
301301
color.Green("[%s] %s %s", "local", ">", color.WhiteString("`%s`", command))
302302

303303
cmd := exec.Command("/bin/sh", "-c", command)
304+
if e.TaskContext != nil && e.TaskContext.Dir != "" {
305+
cmd.Dir = e.TaskContext.Dir
306+
}
304307

305308
stdout, err := cmd.StdoutPipe()
306309
if err != nil {

task.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type task struct {
1818
Name string
1919
Options map[string]*Option
2020
Arguments map[string]*Argument
21+
Dir string
2122

2223
exec *Exec
2324
run taskFunction

utils.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ import (
1717

1818
// Cd is a remote helper function that runs a `cd` before a command
1919
func (e *Exec) Cd(path string) {
20-
command := "cd " + e.Parse(path)
21-
color.Green("[%s] %s %s", e.ServerContext.Name, color.GreenString(">"), command)
22-
e.ServerContext.sshClient.env = command + "; "
20+
dir := e.Parse(path)
21+
if e.TaskContext != nil {
22+
e.TaskContext.Dir = dir
23+
}
24+
if e.ServerContext != nil {
25+
command := "cd " + dir
26+
color.Green("[%s] %s %s", e.ServerContext.Name, color.GreenString(">"), command)
27+
e.ServerContext.sshClient.env = command + "; "
28+
}
2329
}
2430

2531
// CommandExist checks if a remote command exists on server

0 commit comments

Comments
 (0)