More parsing. Go fmt.
This commit is contained in:
parent
d129ff285c
commit
6da2555966
5 changed files with 671 additions and 355 deletions
85
recipe.go
85
recipe.go
|
|
@ -1,57 +1,56 @@
|
|||
|
||||
package main
|
||||
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"os"
|
||||
"io"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
|
||||
// A monolithic function for executing recipes.
|
||||
func executeRecipe(program string,
|
||||
args []string,
|
||||
input string,
|
||||
echo_out bool,
|
||||
echo_err bool,
|
||||
capture_out bool) string {
|
||||
cmd := exec.Command(program, args...)
|
||||
args []string,
|
||||
input string,
|
||||
echo_out bool,
|
||||
echo_err bool,
|
||||
capture_out bool) string {
|
||||
cmd := exec.Command(program, args...)
|
||||
|
||||
if echo_out {
|
||||
cmdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
go io.Copy(os.Stdout, cmdout)
|
||||
}
|
||||
}
|
||||
if echo_out {
|
||||
cmdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
go io.Copy(os.Stdout, cmdout)
|
||||
}
|
||||
}
|
||||
|
||||
if echo_err {
|
||||
cmderr, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
go io.Copy(os.Stderr, cmderr)
|
||||
}
|
||||
}
|
||||
if echo_err {
|
||||
cmderr, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
go io.Copy(os.Stderr, cmderr)
|
||||
}
|
||||
}
|
||||
|
||||
if len(input) > 0 {
|
||||
cmdin, err := cmd.StdinPipe()
|
||||
go func () { cmdin.Write([]byte(input)) }()
|
||||
}
|
||||
if len(input) > 0 {
|
||||
cmdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
go func() { cmdin.Write([]byte(input)) }()
|
||||
}
|
||||
}
|
||||
|
||||
output := ""
|
||||
var err error
|
||||
if capture_out {
|
||||
var outbytes []byte
|
||||
outbytes, err = cmd.Output()
|
||||
output = string(outbytes)
|
||||
} else {
|
||||
err = cmd.Run()
|
||||
}
|
||||
|
||||
output := ""
|
||||
var err error
|
||||
if capture_out {
|
||||
output, err = cmd.Output()
|
||||
} else {
|
||||
err = cmd.Run()
|
||||
}
|
||||
if err != nil {
|
||||
// TODO: better error output
|
||||
log.Fatal("Recipe failed")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// TODO: better error output
|
||||
log.Fatal("Recipe failed")
|
||||
}
|
||||
|
||||
return output
|
||||
return output
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue