Skip to content

Commit

Permalink
Fixes early var expanding, adds support for env vars with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
c2h5oh committed May 19, 2016
1 parent 508b539 commit d5db888
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ func (c *SSHClient) buildComand(task *Task) string {

switch inter {
case "bash", "sh", "zsh", "ksh", "tcsh":
return fmt.Sprintf("/usr/bin/env %s %s -c \"set -x\n%s\"", c.env, i, strings.Replace(task.Run, `"`, `\"`, -1))
return fmt.Sprintf("/usr/bin/env %s %s -c 'set -x\n%s'", c.env, i, strings.Replace(task.Run, `'`, `\'`, -1))

// TODO: add support for python already called via env
case "python", "python3":
return fmt.Sprintf("/usr/bin/env %s %s -c \"%s\"", c.env, i, strings.Replace(task.Run, `"`, `\"`, -1))
return fmt.Sprintf("/usr/bin/env %s %s -c '%s'", c.env, i, strings.Replace(task.Run, `'`, `\'`, -1))

default:
return fmt.Sprintf("/usr/bin/env %s bash -c \"set -x\n%s\"", c.env, strings.Replace(task.Run, `"`, `\"`, -1))
return fmt.Sprintf("/usr/bin/env %s bash -c 'set -x\n%s'", c.env, strings.Replace(task.Run, `'`, `\'`, -1))
}
}
2 changes: 1 addition & 1 deletion sup.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (sup *Stackup) Run(network *Network, commands ...*Command) error {
// `export FOO="bar"; export BAR="baz";`.
env := ``
for _, v := range append(sup.conf.Env, network.Env...) {
env += v.String() + " "
env += v.QuotedString() + " "
}

// Create clients for every host (either SSH or Localhost).
Expand Down
4 changes: 4 additions & 0 deletions supfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (e EnvVar) String() string {
return e.Key + `=` + e.Value
}

func (e EnvVar) QuotedString() string {
return e.Key + `="` + e.Value + `"`
}

// AsExport returns the environment variable as a bash export statement
func (e EnvVar) AsExport() string {
return `export ` + e.Key + `="` + e.Value + `";`
Expand Down

0 comments on commit d5db888

Please sign in to comment.