github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/include.go (about)

     1  package alfred
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/kcmerrill/common.go/config"
     8  )
     9  
    10  func include(task Task, context *Context, tasks map[string]Task) {
    11  	if task.Include == "" {
    12  		return
    13  	}
    14  
    15  	rp := context.relativePath(task.Include)
    16  
    17  	// Does the folder exist? error? boo ...
    18  	if _, err := os.Stat(rp); err != nil {
    19  		context.Ok = false
    20  		return
    21  	}
    22  
    23  	_, contents, err := config.FindAndCombine(rp, context.FileName, "yml")
    24  	if err != nil {
    25  		// cannot use output, no task yet ...
    26  		fmt.Println(translate("{{ .Text.Failure }}{{ .Text.FailureIcon }} Missing task file.{{ .Text.Reset }}", emptyContext()))
    27  		os.Exit(42)
    28  	}
    29  
    30  	context.rootDir = rp
    31  	tasks = AddTasks(contents, context, tasks)
    32  }