Skip to content

Commit

Permalink
New output option to print stdout and stderr
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Kluth <[email protected]>
  • Loading branch information
Alexander Kluth committed Jul 31, 2019
1 parent 767fdb2 commit 89cc13b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
14 changes: 10 additions & 4 deletions Dofile.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ description = "Dofile example"

[tasks]

[tasks.build]
[tasks.ls]
commands = [
'echo "Ja hallo!',
'ls /tmp',
'ls -l'
]

[tasks.clean]
[tasks.date]
commands = [
'echo "Ui ui ui ui ui!"',
'date',
]
output = true

[tasks.fail]
commands = [
'i-do-not-exist'
]
19 changes: 16 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Dofile struct {

type task struct {
Commands []string
Output bool
}

func remove(slice []string, s int) []string {
Expand All @@ -50,9 +51,21 @@ func executeTask(doFile Dofile, taskName string) {
cmdName := tokens[0]
tokens = remove(tokens, 0)

if err := exec.Command(cmdName, tokens...).Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
cmd := exec.Command(cmdName, tokens...)

if doFile.Tasks[taskName].Output == true {
out, _ := cmd.CombinedOutput()

//TODO: Identify if the executable does not exist
//if err != nil {
// log.Fatalf("cmd.Run() failed with %s\n", err)
//}
fmt.Printf(string(out))
} else {
if err := cmd.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
}
} else {
Expand Down

0 comments on commit 89cc13b

Please sign in to comment.