Skip to content

Commit

Permalink
chore: fix sprout
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Aug 25, 2024
1 parent dd297ca commit 500a8b5
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cmd/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"text/template"

"github.com/evcc-io/evcc/util/templates"
"github.com/go-sprout/sprout"
"github.com/go-sprout/sprout/sprigin"
)

type device struct {
Expand Down Expand Up @@ -116,7 +116,7 @@ var configTmpl string

// RenderConfiguration creates a yaml configuration
func (c *Configure) RenderConfiguration() ([]byte, error) {
tmpl, err := template.New("yaml").Funcs(sprout.FuncMap()).Parse(configTmpl)
tmpl, err := template.New("yaml").Funcs(sprigin.FuncMap()).Parse(configTmpl)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/evcc-io/evcc/core"
"github.com/evcc-io/evcc/server"
"github.com/evcc-io/evcc/util/config"
"github.com/go-sprout/sprout"
"github.com/go-sprout/sprout/sprigin"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -70,7 +70,7 @@ func runDump(cmd *cobra.Command, args []string) {

tmpl := template.Must(
template.New("dump").
Funcs(sprout.FuncMap()).
Funcs(sprigin.FuncMap()).
Parse(dumpTmpl))

out := new(bytes.Buffer)
Expand Down
4 changes: 2 additions & 2 deletions cmd/eebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"text/template"

"github.com/evcc-io/evcc/server/eebus"
"github.com/go-sprout/sprout"
"github.com/go-sprout/sprout/sprigin"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -42,7 +42,7 @@ func generateEEBUSCert() {
log.FATAL.Fatal("could not process generated certificate", err)
}

t := template.Must(template.New("out").Funcs(sprout.FuncMap()).Parse(tmpl))
t := template.Must(template.New("out").Funcs(sprigin.FuncMap()).Parse(tmpl))
if err := t.Execute(os.Stdout, map[string]interface{}{
"public": pubKey,
"private": privKey,
Expand Down
4 changes: 2 additions & 2 deletions cmd/tools/decorate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"
"text/template"

"github.com/go-sprout/sprout"
"github.com/go-sprout/sprout/sprigin"
combinations "github.com/mxschmitt/golang-combinations"
"github.com/spf13/pflag"
"golang.org/x/tools/imports"
Expand All @@ -33,7 +33,7 @@ func generate(out io.Writer, packageName, functionName, baseType string, dynamic
types := make(map[string]typeStruct, len(dynamicTypes))
combos := make([]string, 0)

tmpl, err := template.New("gen").Funcs(sprout.FuncMap()).Funcs(template.FuncMap{
tmpl, err := template.New("gen").Funcs(sprigin.FuncMap()).Funcs(template.FuncMap{
// contains checks if slice contains string
"contains": slices.Contains[[]string, string],
// ordered returns a slice of typeStructs ordered by dynamicType
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ require (
)

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/ahmetb/go-linq/v3 v3.2.0 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
Expand Down Expand Up @@ -153,6 +154,8 @@ require (
github.com/mergermarket/go-pkcs7 v0.0.0-20170926155232-153b18ea13c9 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/miekg/dns v1.1.62 // 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.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4yPeE=
Expand Down Expand Up @@ -423,6 +425,8 @@ github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0
github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ=
github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
Expand All @@ -431,6 +435,8 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mlnoga/rct v0.1.2-0.20240421173556-1c5b75037e2f h1:63hbvjkIpccli0EA60fqvzokvU1fH1ZPiNzlF/vUmvM=
github.com/mlnoga/rct v0.1.2-0.20240421173556-1c5b75037e2f/go.mod h1:0lfd2mmBnBzIvuzYtdhG+2371u+cUfIxsYErm4P9KRI=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
6 changes: 3 additions & 3 deletions push/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/evcc-io/evcc/core/vehicle"
"github.com/evcc-io/evcc/util"
"github.com/go-sprout/sprout"
"github.com/go-sprout/sprout/sprigin"
)

// Event is a notification event
Expand Down Expand Up @@ -38,10 +38,10 @@ type Hub struct {
func NewHub(cc map[string]EventTemplateConfig, vv Vehicles, cache *util.Cache) (*Hub, error) {
// instantiate all event templates
for k, v := range cc {
if _, err := template.New("out").Funcs(sprout.FuncMap()).Parse(v.Title); err != nil {
if _, err := template.New("out").Funcs(sprigin.FuncMap()).Parse(v.Title); err != nil {
return nil, fmt.Errorf("invalid event title: %s (%w)", k, err)
}
if _, err := template.New("out").Funcs(sprout.FuncMap()).Parse(v.Msg); err != nil {
if _, err := template.New("out").Funcs(sprigin.FuncMap()).Parse(v.Msg); err != nil {
return nil, fmt.Errorf("invalid event message: %s (%w)", k, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions util/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"time"

"github.com/go-sprout/sprout"
"github.com/go-sprout/sprout/sprigin"
"github.com/samber/lo"
)

Expand Down Expand Up @@ -55,7 +55,7 @@ func FormatValue(format string, val interface{}) string {
func ReplaceFormatted(s string, kv map[string]interface{}) (string, error) {
// Enhanced golang template logic
tpl, err := template.New("base").
Funcs(sprout.FuncMap()).
Funcs(sprigin.FuncMap()).
Funcs(map[string]any{
"timeRound": timeRound,
}).Parse(s)
Expand Down
4 changes: 2 additions & 2 deletions util/templates/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"text/template"

"github.com/go-sprout/sprout"
"github.com/go-sprout/sprout/sprigin"
)

//go:embed documentation.tpl
Expand Down Expand Up @@ -45,7 +45,7 @@ func (t *Template) RenderDocumentation(product Product, lang string) ([]byte, er
var modbusRender string
if modbusChoices := t.ModbusChoices(); len(modbusChoices) > 0 {
if i, _ := t.ParamByName(ParamModbus); i > -1 {
modbusTmpl, err := template.New("yaml").Funcs(sprout.FuncMap()).Parse(documentationModbusTmpl)
modbusTmpl, err := template.New("yaml").Funcs(sprigin.FuncMap()).Parse(documentationModbusTmpl)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions util/templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"text/template"

"github.com/go-sprout/sprout"
"github.com/go-sprout/sprout/sprigin"
)

// Template describes is a proxy device for use with cli and automated testing
Expand Down Expand Up @@ -207,7 +207,7 @@ var proxyTmpl string

// RenderProxyWithValues renders the proxy template
func (t *Template) RenderProxyWithValues(values map[string]interface{}, lang string) ([]byte, error) {
tmpl, err := template.New("yaml").Funcs(sprout.FuncMap()).Parse(proxyTmpl)
tmpl, err := template.New("yaml").Funcs(sprigin.FuncMap()).Parse(proxyTmpl)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions util/templates/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"text/template"

"github.com/go-sprout/sprout"
"github.com/go-sprout/sprout/sprigin"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -59,5 +59,5 @@ func FuncMap(tmpl *template.Template) *template.Template {
"urlEncode": url.QueryEscape,
}

return tmpl.Funcs(sprout.FuncMap()).Funcs(funcMap)
return tmpl.Funcs(sprigin.FuncMap()).Funcs(funcMap)
}

0 comments on commit 500a8b5

Please sign in to comment.