Skip to content

Commit

Permalink
Somewhat functional
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 30, 2019
1 parent 0418e75 commit 5ab9b99
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Dofile.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
description = "Dofile example"

[task]
[tasks]

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

[task.clean]
[tasks.clean]
commands = [
'echo "Ui ui ui ui ui!"',
]
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 42 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/alexflint/go-arg"
"github.com/flynn/go-shlex"
. "github.com/logrusorgru/aurora"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
)

var args struct {
Expand All @@ -15,15 +19,46 @@ var args struct {

type Dofile struct {
Description string
Tasks map[string]Task
Tasks map[string]task
}

type Task struct {
commands []string
type task struct {
Commands []string
}

func executeTask() {
func remove(slice []string, s int) []string {
return append(slice[:s], slice[s+1:]...)
}

func parseCommand(command string) []string {
parts, err := shlex.Split(strings.TrimSpace(command))
if err != nil {
log.Fatal(err)
}

return parts
}

func executeTask(doFile Dofile, taskName string) {
if _, found := doFile.Tasks[taskName]; found {
fmt.Println(Bold(Green("Executing task")), Bold(Cyan(taskName)))

for _, command := range doFile.Tasks[taskName].Commands {
fmt.Println(Bold(Yellow(taskName)), " ", command)

tokens := parseCommand(command)
cmdName := tokens[0]
tokens = remove(tokens, 0)

if err := exec.Command(cmdName, tokens...).Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
} else {
fmt.Println(Bold(Red("Could not find task")), Bold(Yellow(taskName)), Bold(Red("aborting!")))
os.Exit(-1);
}
}

func main() {
Expand All @@ -40,6 +75,8 @@ func main() {
}

for _, taskName := range args.TaskName {
fmt.Println(Bold(Green("Executing task")), Bold(Cyan(taskName)))
executeTask(doFile, taskName)
}

fmt.Println(Bold(Green("Done executing all tasks for")), doFile.Description)
}

0 comments on commit 5ab9b99

Please sign in to comment.