github.com/beauknowssoftware/makehcl@v0.0.0-20200322000747-1b9bb1e1c008/internal/functions/path.go (about)

     1  package functions
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/zclconf/go-cty/cty"
     7  	"github.com/zclconf/go-cty/cty/function"
     8  )
     9  
    10  var PathSpec = function.Spec{
    11  	VarParam: &function.Parameter{Type: cty.String},
    12  	Type:     function.StaticReturnType(cty.String),
    13  	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
    14  		sa := make([]string, 0, len(args))
    15  		for _, a := range args {
    16  			sa = append(sa, a.AsString())
    17  		}
    18  		result := filepath.Join(sa...)
    19  		return cty.StringVal(result), nil
    20  	},
    21  }