Skip to content

Commit 8f551e1

Browse files
committed
Rename template function
1 parent 4543b7a commit 8f551e1

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

docs/actions.schema.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,10 @@ Or type implements `interface { IsEmpty() bool }`.
280280

281281
**Usage:**
282282
```gotemplate
283-
{{ config.Get "foo.bar" }} # retrieves value of any type
284-
{{ index (config.Get "foo.array-elem") 1 }} # retrieves specific array element
285-
{{ config.Get "foo.null-elem" | default "foo" }} # uses default if value is nil
286-
{{ config.Get "foo.missing-elem" | default "bar" }} # uses default if key doesn't exist
283+
{{ config "foo.bar" }} # retrieves value of any type
284+
{{ index (config "foo.array-elem") 1 }} # retrieves specific array element
285+
{{ config "foo.null-elem" | default "foo" }} # uses default if value is nil
286+
{{ config "foo.missing-elem" | default "bar" }} # uses default if key doesn't exist
287287
```
288288

289289

plugins/builtinprocessors/plugin.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func addValueProcessors(tp *action.TemplateProcessors, cfg launchr.Config) {
5252
}
5353
tp.AddValueProcessor(procGetConfigValue, procCfg)
5454
tplCfg := &configTemplateFunc{cfg: cfg}
55-
tp.AddTemplateFunc("config", func() *configTemplateFunc { return tplCfg })
55+
tp.AddTemplateFunc("config", tplCfg.Get)
5656
}
5757

5858
func processorConfigGetByKey(v any, opts ConfigGetProcessorOptions, ctx action.ValueProcessorContext, cfg launchr.Config) (any, error) {
@@ -76,7 +76,7 @@ func processorConfigGetByKey(v any, opts ConfigGetProcessorOptions, ctx action.V
7676
type configKeyNotFound string
7777

7878
// IsEmpty implements a special interface to support "default" template function
79-
// Example: {{ config.Get "foo.bar" | default "buz" }}
79+
// Example: {{ Config "foo.bar" | default "buz" }}
8080
func (s configKeyNotFound) IsEmpty() bool { return true }
8181

8282
// String implements [fmt.Stringer] to output a missing key to a template.
@@ -91,10 +91,10 @@ type configTemplateFunc struct {
9191
//
9292
// Usage:
9393
//
94-
// {{ config.Get "foo.bar" }} - retrieves value of any type
95-
// {{ index (config.Get "foo.array-elem") 1 }} - retrieves specific array element
96-
// {{ config.Get "foo.null-elem" | default "foo" }} - uses default if value is nil
97-
// {{ config.Get "foo.missing-elem" | default "bar" }} - uses default if key doesn't exist
94+
// {{ config "foo.bar" }} - retrieves value of any type
95+
// {{ index (config "foo.array-elem") 1 }} - retrieves specific array element
96+
// {{ config "foo.null-elem" | default "foo" }} - uses default if value is nil
97+
// {{ config "foo.missing-elem" | default "bar" }} - uses default if key doesn't exist
9898
func (t *configTemplateFunc) Get(path string) (any, error) {
9999
var res any
100100
if !t.cfg.Exists(path) {

plugins/builtinprocessors/plugin_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ runtime:
7272
type: container
7373
image: alpine
7474
command:
75-
- '{{ config.Get "my.string" }}'
76-
- '{{ config.Get "my.int" }}'
77-
- '{{ config.Get "my.bool" }}'
78-
- '{{ config.Get "my.array" }}'
79-
- '{{ index (config.Get "my.array") 1 }}'
80-
- '{{ config.Get "my.null" | default "foo" }}'
81-
- '{{ config.Get "my.missing" | default "bar" }}'
75+
- '{{ config "my.string" }}'
76+
- '{{ config "my.int" }}'
77+
- '{{ config "my.bool" }}'
78+
- '{{ config "my.array" }}'
79+
- '{{ index (config "my.array") 1 }}'
80+
- '{{ config "my.null" | default "foo" }}'
81+
- '{{ config "my.missing" | default "bar" }}'
8282
`
8383

8484
const testTplConfigGetMissing = `
@@ -88,7 +88,7 @@ runtime:
8888
type: container
8989
image: alpine
9090
command:
91-
- '{{ config.Get "my.missing" }}'
91+
- '{{ config "my.missing" }}'
9292
`
9393

9494
const testTplConfigGetBadArgs = `
@@ -98,7 +98,7 @@ runtime:
9898
type: container
9999
image: alpine
100100
command:
101-
- '{{ config.Get "my.string" "my.string" }}'
101+
- '{{ config "my.string" "my.string" }}'
102102
`
103103

104104
const testConfig = `
@@ -169,7 +169,7 @@ func Test_ConfigTemplateFunc(t *testing.T) {
169169
tt := []testCase{
170170
{Name: "valid", Yaml: testTplConfigGet, Exp: []string{"my_str", "42", "true", "[1 2 3]", "2", "foo", "bar"}},
171171
{Name: "key not found", Yaml: testTplConfigGetMissing, Exp: []string{"<config key not found \"my.missing\">"}},
172-
{Name: "incorrect call", Yaml: testTplConfigGetBadArgs, Err: "wrong number of args for Get: want 1 got 2"},
172+
{Name: "incorrect call", Yaml: testTplConfigGetBadArgs, Err: "wrong number of args for config: want 1 got 2"},
173173
}
174174
for _, tt := range tt {
175175
tt := tt

0 commit comments

Comments
 (0)