Skip to content

Commit

Permalink
feat(patch): allow arrays to be specified on the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Oct 16, 2023
1 parent 1b8317a commit 5db141d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions cmd/file_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func executePatch(cmd *cobra.Command, args []string) error {
{
var err error
valuesPatch.SelectorSources = cmdPatchSelectors
valuesPatch.ObjValues, valuesPatch.Remove, err = patch.ValidateValuesFlags(cmdPatchValues)
valuesPatch.ObjValues, valuesPatch.Remove, valuesPatch.ArrValues, err = patch.ValidateValuesFlags(cmdPatchValues)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:1.5.0.11)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.2.1.3)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.5.1.2)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.1.4.6)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway-dev:latest)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.6.0.2)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.8)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:3.0)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / test

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values) (typecheck)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / test

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values) (typecheck)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / test

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values) (typecheck)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / test

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values (typecheck)

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:3.1)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong-gateway:2.8)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.0.5)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:3.3)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.1.4)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong/kong:master-alpine)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.5.1)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:3.2)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:3.0)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.3.3)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:1.5.1)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.4.1)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:1.4.3)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values

Check failure on line 35 in cmd/file_patch.go

View workflow job for this annotation

GitHub Actions / integration (kong:2.2.2)

assignment mismatch: 4 variables but patch.ValidateValuesFlags returns 3 values
if err != nil {
return fmt.Errorf("failed parsing '--value' entry; %w", err)
}
Expand Down Expand Up @@ -120,21 +120,30 @@ to the output file. The patches can be specified by a '--selector' and one or mo
'--value' tags, or via patch files.
When using '--selector' and '--values', the items are selected by the 'selector',
which is a JSONpath query. From the array of nodes found, only the objects are updated.
The 'values' are applied on each of the JSONObjects returned by the 'selector'.
which is a JSONpath query. The 'field values' (in '<key:value>' format) are applied on
each of the JSONObjects returned by the 'selector'. The 'array values' (in
'[val1, val2]' format) are appended to each of the JSONArrays returned by the 'selector'.
Objects:
The value must be a valid JSON snippet, so use single/double quotes
The field values must be a valid JSON snippet, so use single/double quotes
appropriately. If the value is empty, the field is removed from the object.
Examples of valid values:
# set field "read_timeout" to a numeric value of 10000
--selector="$..services[*]" --value="read_timeout:10000"
# set field "_comment" to a string value
--selector="$..services[*]" --value='_comment:"comment injected by patching"'
# set field "_ignore" to an array of strings
--selector="$..services[*]" --value='_ignore:["ignore1","ignore2"]'
# remove fields "_ignore" and "_comment" from the object
--selector="$..services[*]" --value='_ignore:' --value='_comment:'
# append entries to the methods array of all route objects
--selector="$..routes[*].methods" --value='["OPTIONS"]'
Patch files have the following format (JSON or YAML) and can contain multiple
patches that are applied in order:
Expand All @@ -153,8 +162,6 @@ patches that are applied in order:
]
}
Arrays:
If the 'values' object instead is an array, then any arrays returned by the selectors
will get the 'values' appended to them.
`,
Expand Down

0 comments on commit 5db141d

Please sign in to comment.