Skip to content

Commit

Permalink
support interactive shell commands in Shell function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryooooooga committed Sep 4, 2021
1 parent 1bb13c4 commit 3a2d4ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.17

- name: Build
run: go build -v ./...
Expand Down
11 changes: 9 additions & 2 deletions pkg/renderer/template_renderer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package renderer

import (
"bytes"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -62,12 +63,18 @@ func (r *TextTemplateRenderer) RenderTemplate(output io.Writer, templateFile *re
}

func shell(command string) (string, error) {
bytes, err := exec.Command("/bin/sh", "-c", command).Output()
var outBuffer bytes.Buffer
cmd := exec.Command("/bin/sh", "-c", command)
cmd.Stdout = &outBuffer
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin

err := cmd.Run()
if err != nil {
return "", err
}

output := string(bytes)
output := outBuffer.String()
output = strings.TrimSuffix(output, "\n")
output = strings.TrimSuffix(output, "\r")
return output, nil
Expand Down

0 comments on commit 3a2d4ce

Please sign in to comment.