File tree Expand file tree Collapse file tree 3 files changed +71
-11
lines changed
Expand file tree Collapse file tree 3 files changed +71
-11
lines changed Original file line number Diff line number Diff line change 1- # yaml-patch
1+ # yaml-patch
2+
3+ Apply patches to a yaml string, keeping most of the formatting and comments.
4+
5+ Some formatting is not kept due to underlying yaml library limitations:
6+ - Indentation will be forced to two spaces
7+ - Spacing before sequence dashes will be forced to two spaces
8+ - Empty lines at the start of the string will be removed
9+
10+ ## As a command line tool
11+
12+ You can pass any number of patches to be applied, they use the following syntax options:
13+
14+ ### Patch a single value:
15+ ` <field>.<subfield>=<value> `
16+
17+ Example:
18+ ``` bash
19+ yaml-patch -f test.yml ' spec.replicas=2'
20+ ```
21+
22+ ### Patch a value inside a single list item:
23+ ` <field>.[<position]>.<subfield>=<value> `
24+
25+ Example:
26+ ``` bash
27+ yaml-patch -f test.yml ' spec.template.containers.[0].image="mycontainer:latest"'
28+ ```
29+
30+ ### Patch a value inside all list items:
31+ ` <field>.[].<subfield>=<value> `
32+
33+ Example:
34+ ``` bash
35+ yaml-patch -f test.yml ' spec.template.containers.[].image="mycontainer:latest"'
36+ ```
37+
38+ ## As a Python library
39+
40+ To use ` yaml-patch ` as a library just import the function and pass patches as dictionary entries.
41+
42+ Example:
43+
44+ ``` python
45+ from yaml_patch import patch
46+ from textwrap import dedent
47+
48+ def override_list_all_values ():
49+ source_yaml = dedent(
50+ """ \
51+ some_list:
52+ - alice
53+ - bob
54+ """
55+ )
56+ patches = {" some_list.[]" : " charlie" }
57+ expected_yaml = dedent(
58+ """ \
59+ some_list:
60+ - charlie
61+ - charlie
62+ """
63+ )
64+ assert patch(source_yaml, patches) == expected_yaml
65+ ```
Original file line number Diff line number Diff line change 88
99@click .command (
1010 help = """
11- Applies patches to a yaml string, keeping most of the formatting and comments.
11+ Apply patches to a yaml string, keeping most of the formatting and comments.
1212
1313\b
1414Some formatting is not kept due to underlying yaml library limitations:
2222Patch a single value:
2323 <field>.<subfield>=<value>
2424Example:
25- spec.replicas=2
25+ yaml-patch -f test.yml ' spec.replicas=2'
2626
2727\b
2828Patch a value inside a single list item:
2929 <field>.[<position]>.<subfield>=<value>
3030Example:
31- spec.template.containers.[0].image="mycontainer:latest"
31+ yaml-patch -f test.yml ' spec.template.containers.[0].image="mycontainer:latest"'
3232
3333\b
3434Patch a value inside all list items:
3535 <field>.[].<subfield>=<value>
3636Example:
37- spec.template.containers.[].image="mycontainer:latest"
38-
39- \b
40- When calling this tool from a command line, it's higly recommended that you quote all patches arguments to avoid terminal issues.
41- Example:
42- yaml-patch -f test.yml 'spec.template.containers.[0].image="mycontainer:latest"'
37+ yaml-patch -f test.yml 'spec.template.containers.[].image="mycontainer:latest"'
4338""" ,
4439)
4540@click .option (
Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ line-length = 120
33
44[tool .poetry ]
55name = " yaml-patch"
6- version = " 0.1.0 "
6+ version = " 0.1.1 "
77description = " Patch yaml strings"
8+ readme = " README.md"
89authors = [" Diogo de Campos <campos.ddc@gmail.com>" ]
910license = " MIT"
1011
You can’t perform that action at this time.
0 commit comments