1
0
mirror of https://github.com/go-task/task.git synced 2024-12-04 10:24:45 +02:00

First working version

This commit is contained in:
Andrey Nering 2017-02-26 20:43:50 -03:00
parent 39e60d6278
commit 389d7f7aed
2 changed files with 65 additions and 1 deletions

2
.gitignore vendored
View File

@ -12,3 +12,5 @@
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
task

64
task.go
View File

@ -1 +1,63 @@
package task
package main
import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"github.com/kardianos/osext"
"gopkg.in/yaml.v2"
)
var (
CurrentDirectory, _ = osext.ExecutableFolder()
TaskFilePath = filepath.Join(CurrentDirectory, "Taskfile.yml")
)
type Task struct {
Cmds []string
Deps []string
Source string
Generates string
}
func main() {
log.SetFlags(0)
args := os.Args[1:]
if len(args) == 0 {
log.Fatal("No argument given")
}
file, err := ioutil.ReadFile(TaskFilePath)
if err != nil {
log.Fatal(err)
}
tasks := make(map[string]*Task)
if err = yaml.Unmarshal(file, &tasks); err != nil {
log.Fatal(err)
}
task, ok := tasks[args[0]]
if !ok {
log.Fatalf(`Task "%s" not found`, args[0])
}
if err = RunTask(task); err != nil {
log.Fatal(err)
}
}
func RunTask(t *Task) error {
for _, c := range t.Cmds {
cmd := exec.Command("/bin/sh", "-c", c)
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
return err
}
}
return nil
}