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
39 lines (31 loc) · 732 Bytes
/
Copy pathrun.go
File metadata and controls
39 lines (31 loc) · 732 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
package cmd
import (
"bufio"
"context"
"fmt"
"os/exec"
"github.com/railwayapp/cli/entity"
)
func (h *Handler) Run(ctx context.Context, req *entity.CommandRequest) error {
envs, err := h.ctrl.GetEnvs(ctx)
argsString := ""
// Inject railway envs
for k, v := range *envs {
argsString += fmt.Sprintf("%s=%+v ", k, v)
}
for _, arg := range req.Args {
argsString += fmt.Sprintf("%s ", arg)
}
bashCommand := exec.Command("bash", "-c", argsString)
pipe, _ := bashCommand.StdoutPipe()
if err := bashCommand.Start(); err != nil {
// handle error
}
reader := bufio.NewReader(pipe)
line, err := reader.ReadString('\n')
for err == nil {
fmt.Println(line)
line, err = reader.ReadString('\n')
}
return nil
}