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
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
builds:
- env:
- CGO_ENABLED=0
flags:
- -trimpath
goos:
- linux
- windows
Expand Down
37 changes: 32 additions & 5 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"strings"
"text/template"

_ "unsafe"

_ "helm.sh/helm/v3/pkg/engine" // Import to work with Helm's private functions (via go linkname)
"github.com/Masterminds/sprig/v3"
)

// Типы токенов для ясности, что мы нашли
Expand Down Expand Up @@ -42,8 +40,37 @@ var (
firstWordRe = regexp.MustCompile(`^\s*(\w+)`)
)

//go:linkname helmFuncMap helm.sh/helm/v3/pkg/engine.funcMap
func helmFuncMap() template.FuncMap
// helmFuncMap mirrors the function set registered by Helm's template engine
// (helm.sh/helm/v3/pkg/engine.funcMap): Sprig's text function map, minus the
// env/expandenv functions Helm removes, plus Helm's own additions. Only the
// presence of each name matters for parse-time syntax validation, so the
// non-Sprig additions are no-op placeholders that are never executed.
func helmFuncMap() template.FuncMap {
f := sprig.TxtFuncMap()
delete(f, "env")
delete(f, "expandenv")

extra := template.FuncMap{
"toToml": func(interface{}) string { return "" },
"fromToml": func(string) map[string]interface{} { return nil },
"toYaml": func(interface{}) string { return "" },
"toYamlPretty": func(interface{}) string { return "" },
"fromYaml": func(string) map[string]interface{} { return nil },
"fromYamlArray": func(string) []interface{} { return nil },
"toJson": func(interface{}) string { return "" },
"fromJson": func(string) map[string]interface{} { return nil },
"fromJsonArray": func(string) []interface{} { return nil },
"include": func(string, interface{}) string { return "" },
"tpl": func(string, interface{}) interface{} { return nil },
"required": func(string, interface{}) (interface{}, error) { return nil, nil },
"lookup": func(string, string, string, string) (map[string]interface{}, error) { return nil, nil },
}
for k, v := range extra {
f[k] = v
}

return f
}

// validateTemplateSyntax validates the given template source string using
// Helm function set. Returns an error if the template has invalid syntax.
Expand Down
49 changes: 6 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,28 @@ module github.com/digitalstudium/helmfmt
go 1.25.1

require (
github.com/Masterminds/sprig/v3 v3.3.0
github.com/spf13/cobra v1.10.1
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.19.0
)

require (
dario.cat/mergo v1.0.1 // indirect
github.com/BurntSushi/toml v1.5.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
github.com/stretchr/testify v1.11.1 // indirect
golang.org/x/crypto v0.42.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/term v0.35.0 // indirect
golang.org/x/text v0.29.0 // indirect
golang.org/x/time v0.12.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.34.0 // indirect
k8s.io/apiextensions-apiserver v0.34.0 // indirect
k8s.io/apimachinery v0.34.0 // indirect
k8s.io/client-go v0.34.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
Loading
Loading