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 27, 2023
1 parent be23beb commit 72dccbc
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cmd/file_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,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 @@ -154,8 +163,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 72dccbc

Please sign in to comment.