forked from railwayapp/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.go
More file actions
42 lines (32 loc) · 670 Bytes
/
Copy pathrun.go
File metadata and controls
42 lines (32 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cmd
import (
"context"
"fmt"
"os"
"os/exec"
"github.com/railwayapp/cli/entity"
"github.com/railwayapp/cli/errors"
)
func (h *Handler) Run(ctx context.Context, req *entity.CommandRequest) error {
envs, err := h.ctrl.GetEnvs(ctx)
if err != nil {
return err
}
if len(req.Args) == 0 {
return errors.CommandNotSpecified
}
cmd := exec.Command(req.Args[0], req.Args[1:]...)
cmd.Env = os.Environ()
// Inject railway envs
for k, v := range *envs {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%+v", k, v))
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
cmd.Stdin = os.Stdin
err = cmd.Run()
if err != nil {
return err
}
return nil
}