Skip to content

Commit

Permalink
add Output to shell
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Vlasic committed Aug 28, 2021
1 parent 63319be commit 7eb708d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/shell/shell.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package shell

import (
"bytes"
"errors"
"io"
"log"
Expand Down Expand Up @@ -151,3 +152,21 @@ func exitCode(err error) int {
}
return 127
}

// TODO: potentially incorporate this into package above
// quick fix just so the functions can build for now
func Output(args []string, path string) (string, error) {
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = path

var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
return "", err
}

outStr, errStr := strings.TrimSpace(stdout.String()), strings.TrimSpace(stderr.String())
return outStr + errStr, nil
}

0 comments on commit 7eb708d

Please sign in to comment.