funcs

package
v0.0.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FileFunc = function.New(&function.Spec{
	Params: []function.Parameter{
		{
			Name: "path",
			Type: cty.String,
		},
	},
	Type: function.StaticReturnType(cty.String),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		f, err := os.ReadFile(args[0].AsString())

		return cty.StringVal(string(f)), err
	},
})

FileFunc reads the contents of the file at the path given. The file must be valid UTF-8.

View Source
var JoinPathFunc = function.New(&function.Spec{
	Params: []function.Parameter{
		{
			Name: "root",
			Type: cty.String,
		},
		{
			Name: "path",
			Type: cty.String,
		},
	},
	Type: function.StaticReturnType(cty.String),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		return cty.StringVal(filepath.ToSlash(filepath.Join(
			args[0].AsString(), args[1].AsString()),
		)), nil
	},
})

JoinPathFunc constructs a function that converts joins two paths.

View Source
var SemverConstraint = function.New(&function.Spec{
	Params: []function.Parameter{
		{
			Name: "version",
			Type: cty.String,
		},
		{
			Name: "constraint",
			Type: cty.String,
		},
	},
	Type: function.StaticReturnType(cty.Bool),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		version, constraint := args[0].AsString(), args[1].AsString()

		v, err := semver.NewVersion(version)
		if err != nil {
			return cty.NullVal(cty.Bool), err
		}

		c, err := semver.NewConstraint(constraint)
		if err != nil {
			return cty.NullVal(cty.Bool), err
		}

		return cty.BoolVal(c.Check(v)), nil
	},
})

SemverConstraint takes a semantic version and a constraint and returns a boolean of whether or not the constaint has been met.

Functions

func AbsPathFunc

func AbsPathFunc(basePath string) function.Function

AbsPathFunc constructs a function that converts a filesystem path to an absolute path. It takes basePath that is equal to the decoders working directory, that way relative paths are relative to the working dir.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL