forked from owenthereal/gotask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.go
73 lines (58 loc) · 1.34 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package task
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/jingweno/gotask/tasking"
)
type TaskSet struct {
Name string
Dir string
PkgObj string
ImportPath string
Tasks []Task
}
func (ts *TaskSet) HasTasks() bool {
return len(ts.Tasks) > 0
}
type Task struct {
Name string
Usage string
Description string
Flags []Flag
ActionName string
Action func(*tasking.T)
}
func (t *Task) ToCLIFlags() (flags []cli.Flag) {
for _, flag := range t.Flags {
flags = append(flags, flag)
}
return
}
type Flag interface {
cli.Flag
DefType(importAsPkg string) string
}
type BoolFlag struct {
cli.BoolFlag
}
func (f BoolFlag) getName() string {
return f.Name
}
func (f BoolFlag) DefType(importAsPkg string) string {
return fmt.Sprintf(`%s.NewBoolFlag("%s", "%s")`, importAsPkg, f.Name, f.Usage)
}
func NewBoolFlag(name, usage string) BoolFlag {
return BoolFlag{cli.BoolFlag{Name: name, Usage: usage}}
}
type StringFlag struct {
cli.StringFlag
}
func (f StringFlag) getName() string {
return f.Name
}
func (f StringFlag) DefType(importAsPkg string) string {
return fmt.Sprintf(`%s.NewStringFlag("%s", "%s", "%s")`, importAsPkg, f.Name, f.Value, f.Usage)
}
func NewStringFlag(name, value, usage string) StringFlag {
return StringFlag{cli.StringFlag{Name: name, Value: value, Usage: usage}}
}