Skip to content

Commit 7ceefc9

Browse files
committed
Implement --realize
1 parent 68caa5f commit 7ceefc9

16 files changed

+138
-57
lines changed

docs/sections/user_guide/cli/tools/config.rst

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,46 @@ Examples
115115
:caption: compose-update-2.yaml
116116
:language: yaml
117117

118-
Compose the three together, writing to ``stdout``:
118+
Compose the three together, writing to ``stdout``:
119119

120-
.. literalinclude:: config/compose-1.cmd
121-
:language: text
122-
:emphasize-lines: 1
123-
.. literalinclude:: config/compose-1.out
124-
:language: yaml
120+
.. literalinclude:: config/compose-basic.cmd
121+
:language: text
122+
:emphasize-lines: 1
123+
.. literalinclude:: config/compose-basic.out
124+
:language: yaml
125+
126+
Values provided by update configs override or augment values provided in the base config, while unaffected values survive to the final config. Priority of values increases from left to right.
127+
128+
Additionally:
129+
130+
* Sets of configs in the ``ini``, ``nml``, and ``sh`` formats can be similarly composed.
131+
* The ``--input-format`` and ``--output-format`` options can be used to specify the format of the input and output configs, respectively, for cases when ``uwtools`` cannot deduce the format of configs from their filename extensions. When the formats are neither explicitly specified or deduced, ``yaml`` is assumed.
132+
* The ``--output-file`` / ``-o`` option can be added to write the final config to a file instead of to ``stdout``.
133+
134+
* The optional ``--realize`` switch can be used to render as many Jinja2 template expressions as possible in the final config, using the config itself as a source of values. For example:
125135

126-
Values provided by update configs override or augment values provided in the base config, while unaffected values survive to the final config. Priority of values increases from left to right.
136+
.. literalinclude:: config/compose-template.yaml
137+
:caption: compose-template.yaml
138+
:language: yaml
139+
.. literalinclude:: config/compose-values.yaml
140+
:caption: compose-values.yaml
141+
:language: yaml
142+
143+
Without the ``--realize`` switch:
144+
145+
.. literalinclude:: config/compose-realize-no.cmd
146+
:language: text
147+
:emphasize-lines: 1
148+
.. literalinclude:: config/compose-realize-no.out
149+
:language: yaml
127150

128-
Additionally:
151+
And with ``--realize``:
129152

130-
* Sets of configs in the ``ini``, ``nml``, and ``sh`` formats can be similarly composed.
131-
* The ``--input-format`` and ``--output-format`` options can be used to specify the format of the input and output configs, respectively, for cases when ``uwtools`` cannot deduce the format of configs from their filename extensions. When the formats are neither explicitly specified or deduced, ``yaml`` is assumed.
132-
* The ``--output-file`` / ``-o`` option can be added to write the final config to a file instead of to ``stdout``.
153+
.. literalinclude:: config/compose-realize-yes.cmd
154+
:language: text
155+
:emphasize-lines: 1
156+
.. literalinclude:: config/compose-realize-yes.out
157+
:language: yaml
133158

134159
.. _cli_config_realize_examples:
135160

File renamed without changes.
File renamed without changes.

docs/sections/user_guide/cli/tools/config/compose-help.out

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
usage: uw config compose [-h] [--version] [--input-format {ini,nml,sh,yaml}]
2-
[--output-format {ini,nml,sh,yaml}]
3-
[--output-file PATH] [--quiet] [--verbose]
1+
usage: uw config compose [-h] [--version] [--realize] [--output-file PATH]
2+
[--input-format {ini,nml,sh,yaml}]
3+
[--output-format {ini,nml,sh,yaml}] [--quiet]
4+
[--verbose]
45
CONFIG [CONFIG ...]
56

67
Compose configs
@@ -13,12 +14,14 @@ Optional arguments:
1314
Show help and exit
1415
--version
1516
Show version info and exit
17+
--realize
18+
Try to render template expressions
19+
--output-file PATH, -o PATH
20+
Path to output file (default: write to stdout)
1621
--input-format {ini,nml,sh,yaml}
1722
Input format (default: yaml)
1823
--output-format {ini,nml,sh,yaml}
1924
Output format (default: yaml)
20-
--output-file PATH, -o PATH
21-
Path to output file (default: write to stdout)
2225
--quiet, -q
2326
Print no logging messages
2427
--verbose, -v
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uw config compose compose-template.yaml compose-values.yaml
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
radius: !float '{{ 2.0 * pi * r }}'
2+
pi: 3.142
3+
r: 1.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uw config compose compose-template.yaml compose-values.yaml --realize
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
radius: 6.284
2+
pi: 3.142
3+
r: 1.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
radius: !float '{{ 2.0 * pi * r }}'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pi: 3.142
2+
r: 1.0

0 commit comments

Comments
 (0)