-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#96 Step can pass results of command to another step
- Loading branch information
Showing
8 changed files
with
4,131 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: job4 # name of recipe | ||
definition: schedule | ||
schedule: | ||
min: 0 | ||
hour: 0 | ||
day: 0 | ||
|
||
steps: # steps are done from first to last | ||
- echo "I like golang" }> | ||
- cat > i_like_it.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package workers | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
// PipeMarker is string that we mark when we want to pipe output of results | ||
// from step command to another step command | ||
const PipeMarker = "}>" | ||
|
||
type cmd struct { | ||
stdin bytes.Buffer | ||
cmd *exec.Cmd | ||
stdout bytes.Buffer | ||
pipe bool | ||
} | ||
|
||
func (c *cmd) Run() error { | ||
if &c.stdin != nil { | ||
in, err := c.cmd.StdinPipe() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = io.WriteString(in, string(c.stdin.Bytes())) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
var stderr bytes.Buffer | ||
c.cmd.Stdout = &c.stdout | ||
c.cmd.Stderr = &stderr | ||
|
||
err := c.cmd.Run() | ||
|
||
return err | ||
} | ||
|
||
// NewCmd build new command and prepare it to be run | ||
func newCmd(step string, i bytes.Buffer) (*cmd, error) { | ||
cmd := &cmd{ | ||
stdin: i, | ||
pipe: false, | ||
} | ||
|
||
s := strings.Fields(step) | ||
if s[len(s)-1] == PipeMarker { | ||
cmd.pipe = true | ||
step = strings.Join(s[:(len(s)-1)], " ") | ||
} | ||
|
||
cmd.cmd = exec.Command("bash", "-c", step) | ||
|
||
return cmd, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters