@@ -2,13 +2,16 @@ package main
22
33import (
44 "fmt"
5+ "log"
56
67 "github.com/go-task/task"
78
89 "github.com/spf13/pflag"
910)
1011
1112func main () {
13+ log .SetFlags (0 )
14+
1215 pflag .Usage = func () {
1316 fmt .Println (`task [target1 target2 ...]: Runs commands under targets like make.
1417
@@ -25,9 +28,40 @@ hello:
2528` )
2629 pflag .PrintDefaults ()
2730 }
28- pflag .BoolVarP (& task .Init , "init" , "i" , false , "creates a new Taskfile.yml in the current folder" )
29- pflag .BoolVarP (& task .Force , "force" , "f" , false , "forces execution even when the task is up-to-date" )
30- pflag .BoolVarP (& task .Watch , "watch" , "w" , false , "enables watch of the given task" )
31+
32+ var (
33+ init bool
34+ force bool
35+ watch bool
36+ )
37+
38+ pflag .BoolVarP (& init , "init" , "i" , false , "creates a new Taskfile.yml in the current folder" )
39+ pflag .BoolVarP (& force , "force" , "f" , false , "forces execution even when the task is up-to-date" )
40+ pflag .BoolVarP (& watch , "watch" , "w" , false , "enables watch of the given task" )
3141 pflag .Parse ()
32- task .Run ()
42+
43+ if init {
44+ if err := task .InitTaskfile (); err != nil {
45+ log .Fatal (err )
46+ }
47+ return
48+ }
49+
50+ e := task.Executor {
51+ Force : force ,
52+ Watch : watch ,
53+ }
54+ if err := e .ReadTaskfile (); err != nil {
55+ log .Fatal (err )
56+ }
57+
58+ args := pflag .Args ()
59+ if len (args ) == 0 {
60+ log .Println ("task: No argument given, trying default task" )
61+ args = []string {"default" }
62+ }
63+
64+ if err := e .Run (args ... ); err != nil {
65+ log .Fatal (err )
66+ }
3367}
0 commit comments