Cleanup
This commit is contained in:
parent
c29b8b8200
commit
9bc09b72f5
@ -33,10 +33,9 @@ import (
|
||||
)
|
||||
|
||||
type config struct {
|
||||
Tasks map[string]task
|
||||
Macros map[string]macro
|
||||
Tasks map[string]*task
|
||||
Macros map[string]*macro
|
||||
|
||||
handled map[string]bool
|
||||
srcDir string
|
||||
dstDir string
|
||||
variant string
|
||||
@ -49,7 +48,7 @@ func newConfig(filename string) (*config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conf := &config{handled: make(map[string]bool)}
|
||||
conf := new(config)
|
||||
switch path.Ext(filename) {
|
||||
case ".json":
|
||||
if err := json.Unmarshal(bytes, &conf); err != nil {
|
||||
|
28
task.go
28
task.go
@ -29,6 +29,8 @@ type task struct {
|
||||
Links [][]string
|
||||
Cmds [][]string
|
||||
Envs [][]string
|
||||
|
||||
handled bool
|
||||
}
|
||||
|
||||
func (t *task) process(conf *config) error {
|
||||
@ -64,17 +66,25 @@ func (t *task) process(conf *config) error {
|
||||
}
|
||||
|
||||
func processTask(taskName string, conf *config) error {
|
||||
handled, ok := conf.handled[taskName]
|
||||
if ok && handled {
|
||||
var taskNames []string
|
||||
if len(conf.variant) > 0 {
|
||||
taskNames = append(taskNames, fmt.Sprint(taskName, "%", conf.variant))
|
||||
}
|
||||
taskNames = append(taskNames, taskName)
|
||||
|
||||
for _, tn := range taskNames {
|
||||
t, ok := conf.Tasks[tn]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if t.handled {
|
||||
return nil
|
||||
}
|
||||
|
||||
conf.handled[taskName] = true
|
||||
|
||||
t, ok := conf.Tasks[taskName]
|
||||
if !ok {
|
||||
return fmt.Errorf("task not found: %s", taskName)
|
||||
}
|
||||
|
||||
t.handled = true
|
||||
return t.process(conf)
|
||||
}
|
||||
|
||||
return fmt.Errorf("task or variant not found: %s", taskName)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user