1
0
mirror of https://github.com/go-task/task.git synced 2025-06-23 00:38:19 +02:00

added yml/json/toml support, --help flag, and example directory

Signed-off-by: Andrey Nering <andrey.nering@gmail.com>
This commit is contained in:
Travis
2017-02-28 08:13:48 -08:00
committed by Andrey Nering
parent a15cf26842
commit 61b1aa8559
4 changed files with 64 additions and 9 deletions

31
task.go
View File

@ -1,18 +1,21 @@
package task
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"github.com/BurntSushi/toml"
"gopkg.in/yaml.v2"
)
var (
// TaskFilePath is the default Taskfile
TaskFilePath = "Taskfile.yml"
TaskFilePath = "Taskfile"
// ShExists is true if Bash was found
ShExists bool
// ShPath constains the Bash path if found
@ -65,15 +68,9 @@ func Run() {
log.Fatal("No argument given")
}
file, err := ioutil.ReadFile(TaskFilePath)
var err error
Tasks, err = readTaskfile()
if err != nil {
if os.IsNotExist(err) {
log.Fatal("Taskfile.yml not found")
}
log.Fatal(err)
}
if err = yaml.Unmarshal(file, &Tasks); err != nil {
log.Fatal(err)
}
@ -142,3 +139,19 @@ func runCommand(c string) error {
}
return nil
}
func readTaskfile() (tasks map[string]*Task, err error) {
if b, err := ioutil.ReadFile(TaskFilePath + ".yml"); err == nil {
return tasks, yaml.Unmarshal(b, &tasks)
}
if b, err := ioutil.ReadFile(TaskFilePath + ".json"); err == nil {
return tasks, json.Unmarshal(b, &tasks)
}
if b, err := ioutil.ReadFile(TaskFilePath + ".toml"); err == nil {
return tasks, toml.Unmarshal(b, &tasks)
}
return nil, ErrNoTaskFile
}
// ErrNoTaskFile is returns when the program can not find a proper TaskFile
var ErrNoTaskFile = errors.New("no task file found (is it named '" + TaskFilePath + "'?)")