Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/exprenv/exprenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func BaseFuncs(ptyEnabled bool) map[string]any {
"truncate": exprfuncs.Truncate,
"substr": exprfuncs.Substr,
"formatOrder": exprfuncs.FormatOrder,
"env": exprfuncs.Env,
}
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/exprenv/exprfuncs/exprfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package exprfuncs
import (
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -414,3 +415,15 @@ func IsBlank(v any) bool {
s, ok := v.(string)
return ok && s == ""
}

// Env returns the value of the named environment variable, or def (default "")
// when it is unset or empty.
func Env(name string, def ...string) string {
if v := os.Getenv(name); v != "" {
return v
}
if len(def) > 0 {
return def[0]
}
return ""
}
Loading