Within the sh package, args are being expanded in the case where normal sh command would not expand args within single quotes. Example command:
pact-broker create-webhook --user='admin:${user.bitbucketAppPassword}'
- Via normal shell the single quotes will not expand
${user.bitbucketAppPassword}
- Via mage the expansion occurs and the actual command becomes:
pact-broker create-webhook --user='admin:'
|
// Exec executes the command, piping its stderr to mage's stderr and |
|
// piping its stdout to the given writer. If the command fails, it will return |
|
// an error that, if returned from a target or mg.Deps call, will cause mage to |
|
// exit with the same code as the command failed with. Env is a list of |
|
// environment variables to set when running the command, these override the |
|
// current environment variables set (which are also passed to the command). cmd |
|
// and args may include references to environment variables in $FOO format, in |
|
// which case these will be expanded before the command is run. |
|
// |
|
// Ran reports if the command ran (rather than was not found or not executable). |
|
// Code reports the exit code the command returned if it ran. If err == nil, ran |
|
// is always true and code is always 0. |
|
func Exec(env map[string]string, stdout, stderr io.Writer, cmd string, args ...string) (ran bool, err error) { |
|
expand := func(s string) string { |
|
s2, ok := env[s] |
|
if ok { |
|
return s2 |
|
} |
|
return os.Getenv(s) |
|
} |
|
cmd = os.Expand(cmd, expand) |
|
for i := range args { |
|
args[i] = os.Expand(args[i], expand) |
|
} |
Within the
shpackage, args are being expanded in the case where normal sh command would not expand args within single quotes. Example command:pact-broker create-webhook --user='admin:${user.bitbucketAppPassword}'${user.bitbucketAppPassword}pact-broker create-webhook --user='admin:'mage/sh/cmd.go
Lines 92 to 115 in 26cdb5c