File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -29,13 +29,39 @@ type Pipe struct {
29
29
30
30
// wd is the working directory for current pipe.
31
31
wd string
32
+ // env is the environment variables for current pipe.
33
+ // Non-empty value will be set to the exec.Command instance.
34
+ env []string
32
35
}
33
36
34
37
func (p * Pipe ) At (dir string ) * Pipe {
35
38
p .wd = dir
36
39
return p
37
40
}
38
41
42
+ // WithCurrentEnv sets the environment variables to the current process's environment.
43
+ func (p * Pipe ) WithCurrentEnv () * Pipe {
44
+ return p .WithEnv (os .Environ ())
45
+ }
46
+
47
+ // WithEnv sets the environment variables for the current pipe.
48
+ func (p * Pipe ) WithEnv (env []string ) * Pipe {
49
+ p .env = env
50
+ return p
51
+ }
52
+
53
+ // AppendEnv appends the environment variables for the current pipe.
54
+ func (p * Pipe ) AppendEnv (env ... string ) * Pipe {
55
+ p .env = append (p .env , env ... )
56
+ return p
57
+ }
58
+
59
+ // WithEnvKV sets the environment variable key-value pair for the current pipe.
60
+ func (p * Pipe ) WithEnvKV (key , value string ) * Pipe {
61
+ p .env = append (p .env , key + "=" + value )
62
+ return p
63
+ }
64
+
39
65
func (p * Pipe ) WithStderr (w io.Writer ) * Pipe {
40
66
p .stderr = w
41
67
p .Pipe = p .Pipe .WithStderr (w )
@@ -106,6 +132,9 @@ func (p *Pipe) execContext(
106
132
if p .wd != "" {
107
133
cmd .Dir = p .wd
108
134
}
135
+ if len (p .env ) > 0 {
136
+ cmd .Env = p .env
137
+ }
109
138
110
139
return cmd
111
140
}
You can’t perform that action at this time.
0 commit comments