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

     1  package functions
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  
     7  	"github.com/zclconf/go-cty/cty"
     8  	"github.com/zclconf/go-cty/cty/function"
     9  )
    10  
    11  var FilenameSpec = function.Spec{
    12  	Params: []function.Parameter{
    13  		{Type: cty.String},
    14  	},
    15  	Type: function.StaticReturnType(cty.String),
    16  	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
    17  		path := args[0].AsString()
    18  		ext := filepath.Ext(path)
    19  		result := strings.TrimSuffix(path, ext)
    20  		return cty.StringVal(result), nil
    21  	},
    22  }