1
1
package client
2
2
3
3
import (
4
+ "fmt"
4
5
"io"
5
6
"os"
6
7
"os/exec"
@@ -17,15 +18,26 @@ type ProgramFunc func(args ...string) Program
17
18
18
19
// NewShellProgramFunc creates programs that are executed in a Shell.
19
20
func NewShellProgramFunc (name string ) ProgramFunc {
21
+ return NewShellProgramFuncWithEnv (name , nil )
22
+ }
23
+
24
+ // NewShellProgramFuncWithEnv creates programs that are executed in a Shell with environment variables
25
+ func NewShellProgramFuncWithEnv (name string , env * map [string ]string ) ProgramFunc {
20
26
return func (args ... string ) Program {
21
- return & Shell {cmd : newCmdRedirectErr (name , args )}
27
+ return & Shell {cmd : createProgramCmdRedirectErr (name , args , env )}
22
28
}
23
29
}
24
30
25
- func newCmdRedirectErr (name string , args []string ) * exec.Cmd {
26
- newCmd := exec .Command (name , args ... )
27
- newCmd .Stderr = os .Stderr
28
- return newCmd
31
+ func createProgramCmdRedirectErr (commandName string , args []string , env * map [string ]string ) * exec.Cmd {
32
+ programCmd := exec .Command (commandName , args ... )
33
+ programCmd .Env = os .Environ ()
34
+ if env != nil {
35
+ for k , v := range * env {
36
+ programCmd .Env = append (programCmd .Env , fmt .Sprintf ("%s=%s" , k , v ))
37
+ }
38
+ }
39
+ programCmd .Stderr = os .Stderr
40
+ return programCmd
29
41
}
30
42
31
43
// Shell invokes shell commands to talk with a remote credentials helper.
0 commit comments