-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c09642
commit a178fe6
Showing
3 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,65 @@ | ||
# yaml-patch | ||
# yaml-patch | ||
|
||
Apply patches to a yaml string, keeping most of the formatting and comments. | ||
|
||
Some formatting is not kept due to underlying yaml library limitations: | ||
- Indentation will be forced to two spaces | ||
- Spacing before sequence dashes will be forced to two spaces | ||
- Empty lines at the start of the string will be removed | ||
|
||
## As a command line tool | ||
|
||
You can pass any number of patches to be applied, they use the following syntax options: | ||
|
||
### Patch a single value: | ||
`<field>.<subfield>=<value>` | ||
|
||
Example: | ||
```bash | ||
yaml-patch -f test.yml 'spec.replicas=2' | ||
``` | ||
|
||
### Patch a value inside a single list item: | ||
`<field>.[<position]>.<subfield>=<value>` | ||
|
||
Example: | ||
```bash | ||
yaml-patch -f test.yml 'spec.template.containers.[0].image="mycontainer:latest"' | ||
``` | ||
|
||
### Patch a value inside all list items: | ||
`<field>.[].<subfield>=<value>` | ||
|
||
Example: | ||
```bash | ||
yaml-patch -f test.yml 'spec.template.containers.[].image="mycontainer:latest"' | ||
``` | ||
|
||
## As a Python library | ||
|
||
To use `yaml-patch` as a library just import the function and pass patches as dictionary entries. | ||
|
||
Example: | ||
|
||
```python | ||
from yaml_patch import patch | ||
from textwrap import dedent | ||
|
||
def override_list_all_values(): | ||
source_yaml = dedent( | ||
"""\ | ||
some_list: | ||
- alice | ||
- bob | ||
""" | ||
) | ||
patches = {"some_list.[]": "charlie"} | ||
expected_yaml = dedent( | ||
"""\ | ||
some_list: | ||
- charlie | ||
- charlie | ||
""" | ||
) | ||
assert patch(source_yaml, patches) == expected_yaml | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ line-length = 120 | |
|
||
[tool.poetry] | ||
name = "yaml-patch" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
description = "Patch yaml strings" | ||
readme = "README.md" | ||
authors = ["Diogo de Campos <[email protected]>"] | ||
license = "MIT" | ||
|
||
|