From a9744de11391261efbd2a366640782c2e15b00d9 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sun, 23 Oct 2022 12:42:13 -0400 Subject: [PATCH] Deprecate non-pipelineable strings aliases Signed-off-by: Dave Henderson --- docs-src/content/functions/strings.yml | 6 +++ docs/content/functions/strings.md | 18 +++++--- funcs/strings.go | 64 +++++++++++++++++++++++--- 3 files changed, 76 insertions(+), 12 deletions(-) diff --git a/docs-src/content/functions/strings.yml b/docs-src/content/functions/strings.yml index b72f7f7b2..7bd02ac35 100644 --- a/docs-src/content/functions/strings.yml +++ b/docs-src/content/functions/strings.yml @@ -523,6 +523,7 @@ funcs: 0 is 1 bytes and 1 runes ᐰ is 3 bytes and 1 runes - name: contains + deprecated: Use [`strings.Contains`](#strings-contains) instead description: | **See [`strings.Contains`](#strings-contains) for a pipeline-compatible version** @@ -550,6 +551,7 @@ funcs: no ``` - name: hasPrefix + deprecated: Use [`strings.HasPrefix`](#strings-hasprefix) instead description: | **See [`strings.HasPrefix`](#strings-hasprefix) for a pipeline-compatible version** @@ -577,6 +579,7 @@ funcs: foo ``` - name: hasSuffix + deprecated: Use [`strings.HasSuffix`](#strings-hassuffix) instead description: | **See [`strings.HasSuffix`](#strings-hassuffix) for a pipeline-compatible version** @@ -602,6 +605,7 @@ funcs: http://example.com:80 ``` - name: split + deprecated: Use [`strings.Split`](#strings-split) instead description: | **See [`strings.Split`](#strings-split) for a pipeline-compatible version** @@ -623,6 +627,7 @@ funcs: Hello, Lisa Hello, Maggie - name: splitN + deprecated: Use [`strings.SplitN`](#strings-splitn) instead description: | **See [`strings.SplitN`](#strings-splitn) for a pipeline-compatible version** @@ -646,6 +651,7 @@ funcs: foo bar:baz - name: trim + deprecated: Use [`strings.Trim`](#strings-trim) instead description: | **See [`strings.Trim`](#strings-trim) for a pipeline-compatible version** diff --git a/docs/content/functions/strings.md b/docs/content/functions/strings.md index dc00267eb..dcbcda454 100644 --- a/docs/content/functions/strings.md +++ b/docs/content/functions/strings.md @@ -877,7 +877,8 @@ $ gomplate -i '{{ range (coll.Slice "\u03a9" "\u0030" "\u1430") }}{{ printf "%s ᐰ is 3 bytes and 1 runes ``` -## `contains` +## `contains` _(deprecated)_ +**Deprecation Notice:** Use [`strings.Contains`](#strings-contains) instead **See [`strings.Contains`](#strings-contains) for a pipeline-compatible version** @@ -911,7 +912,8 @@ $ FOO=bar gomplate < input.tmpl no ``` -## `hasPrefix` +## `hasPrefix` _(deprecated)_ +**Deprecation Notice:** Use [`strings.HasPrefix`](#strings-hasprefix) instead **See [`strings.HasPrefix`](#strings-hasprefix) for a pipeline-compatible version** @@ -945,7 +947,8 @@ $ URL=https://example.com gomplate < input.tmpl foo ``` -## `hasSuffix` +## `hasSuffix` _(deprecated)_ +**Deprecation Notice:** Use [`strings.HasSuffix`](#strings-hassuffix) instead **See [`strings.HasSuffix`](#strings-hassuffix) for a pipeline-compatible version** @@ -977,7 +980,8 @@ $ URL=http://example.com gomplate < input.tmpl http://example.com:80 ``` -## `split` +## `split` _(deprecated)_ +**Deprecation Notice:** Use [`strings.Split`](#strings-split) instead **See [`strings.Split`](#strings-split) for a pipeline-compatible version** @@ -1007,7 +1011,8 @@ Hello, Lisa Hello, Maggie ``` -## `splitN` +## `splitN` _(deprecated)_ +**Deprecation Notice:** Use [`strings.SplitN`](#strings-splitn) instead **See [`strings.SplitN`](#strings-splitn) for a pipeline-compatible version** @@ -1037,7 +1042,8 @@ foo bar:baz ``` -## `trim` +## `trim` _(deprecated)_ +**Deprecation Notice:** Use [`strings.Trim`](#strings-trim) instead **See [`strings.Trim`](#strings-trim) for a pipeline-compatible version** diff --git a/funcs/strings.go b/funcs/strings.go index 65e4a6f29..ab59c0c9f 100644 --- a/funcs/strings.go +++ b/funcs/strings.go @@ -58,12 +58,12 @@ func CreateStringFuncs(ctx context.Context) map[string]interface{} { f["squote"] = ns.Squote // these are legacy aliases with non-pipelinable arg order - f["contains"] = strings.Contains - f["hasPrefix"] = strings.HasPrefix - f["hasSuffix"] = strings.HasSuffix - f["split"] = strings.Split - f["splitN"] = strings.SplitN - f["trim"] = strings.Trim + f["contains"] = ns.oldContains + f["hasPrefix"] = ns.oldHasPrefix + f["hasSuffix"] = ns.oldHasSuffix + f["split"] = ns.oldSplit + f["splitN"] = ns.oldSplitN + f["trim"] = ns.oldTrim return f } @@ -77,6 +77,58 @@ type StringFuncs struct { tag language.Tag } +// ---- legacy aliases with non-pipelinable arg order + +// oldContains - +// +// Deprecated: use [strings.Contains] instead +func (f *StringFuncs) oldContains(s, substr string) bool { + deprecated.WarnDeprecated(f.ctx, "contains is deprecated - use strings.Contains instead") + return strings.Contains(s, substr) +} + +// oldHasPrefix - +// +// Deprecated: use [strings.HasPrefix] instead +func (f *StringFuncs) oldHasPrefix(s, prefix string) bool { + deprecated.WarnDeprecated(f.ctx, "hasPrefix is deprecated - use strings.HasPrefix instead") + return strings.HasPrefix(s, prefix) +} + +// oldHasSuffix - +// +// Deprecated: use [strings.HasSuffix] instead +func (f *StringFuncs) oldHasSuffix(s, suffix string) bool { + deprecated.WarnDeprecated(f.ctx, "hasSuffix is deprecated - use strings.HasSuffix instead") + return strings.HasSuffix(s, suffix) +} + +// oldSplit - +// +// Deprecated: use [strings.Split] instead +func (f *StringFuncs) oldSplit(s, sep string) []string { + deprecated.WarnDeprecated(f.ctx, "split is deprecated - use strings.Split instead") + return strings.Split(s, sep) +} + +// oldSplitN - +// +// Deprecated: use [strings.SplitN] instead +func (f *StringFuncs) oldSplitN(s, sep string, n int) []string { + deprecated.WarnDeprecated(f.ctx, "splitN is deprecated - use strings.SplitN instead") + return strings.SplitN(s, sep, n) +} + +// oldTrim - +// +// Deprecated: use [strings.Trim] instead +func (f *StringFuncs) oldTrim(s, cutset string) string { + deprecated.WarnDeprecated(f.ctx, "trim is deprecated - use strings.Trim instead") + return strings.Trim(s, cutset) +} + +// ---- + // Abbrev - func (StringFuncs) Abbrev(args ...interface{}) (string, error) { str := ""