feat: add joinEnv and joinUrl string functions and 2 new system vars (#2408)

This commit is contained in:
Jerry Wiltse
2026-05-09 10:19:33 -04:00
committed by GitHub
parent 629a10813f
commit d9e0e04725
4 changed files with 101 additions and 18 deletions

View File

@@ -285,7 +285,9 @@ func isEnvVar(key string, envVars map[string]bool) bool {
key == "TASKFILE_DIR" ||
key == "USER_WORKING_DIR" ||
key == "ALIAS" ||
key == "MATCH" {
key == "MATCH" ||
key == "PATH_LIST_SEPARATOR" ||
key == "FILE_PATH_SEPARATOR" {
return true
}
return envVars[key]

View File

@@ -3,6 +3,8 @@ package templater
import (
"maps"
"math/rand/v2"
"os"
"path"
"path/filepath"
"runtime"
"strings"
@@ -21,8 +23,8 @@ var templateFuncs template.FuncMap
func init() {
taskFuncs := template.FuncMap{
"OS": os,
"ARCH": arch,
"OS": goos,
"ARCH": goarch,
"numCPU": runtime.NumCPU,
"catLines": catLines,
"splitLines": splitLines,
@@ -33,6 +35,8 @@ func init() {
"splitArgs": splitArgs,
"IsSH": IsSH, // Deprecated
"joinPath": filepath.Join,
"joinEnv": joinEnv,
"joinUrl": joinUrl,
"relPath": filepath.Rel,
"absPath": filepath.Abs,
"merge": merge,
@@ -57,11 +61,11 @@ func init() {
maps.Copy(templateFuncs, taskFuncs)
}
func os() string {
func goos() string {
return runtime.GOOS
}
func arch() string {
func goarch() string {
return runtime.GOARCH
}
@@ -95,6 +99,14 @@ func IsSH() bool {
return true
}
func joinEnv(elem ...string) string {
return strings.Join(elem, string(os.PathListSeparator))
}
func joinUrl(elem ...string) string {
return path.Join(elem...)
}
func merge(base map[string]any, v ...map[string]any) map[string]any {
cap := len(v)
for _, m := range v {