Skip to content

Commit 36d95f9

Browse files
authored
Add details of -z option (#618)
1 parent 671361a commit 36d95f9

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

src/7-to-8/major-changes/template-vars.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Example
5858
New Features
5959
------------
6060

61+
Any valid Python literals
62+
^^^^^^^^^^^^^^^^^^^^^^^^^
63+
6164
Template variables can now be any valid Python literals e.g:
6265

6366
.. code-block:: python
@@ -73,3 +76,20 @@ Template variables can now be any valid Python literals e.g:
7376
{"a": 1, "b": 2, "c": 3} # dictionary
7477
7578
See :ref:`jinja2-template-variables` for more information.
79+
80+
Shorthand for list of strings
81+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82+
83+
.. versionadded:: 8.2
84+
85+
A new shorthand argument (``-z``/``--set-list``/``--set-template``)
86+
has been introduced allowing easier definition of template
87+
variables containing lists of strings on the command line:
88+
89+
.. code-block:: shell
90+
91+
# Before (still works)
92+
cylc <command> --set "X=['a', 'b', 'c']"
93+
94+
# After
95+
cylc <command> --set-list X=a,b,c

src/user-guide/writing-workflows/jinja2.rst

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ not in the ``environ`` dict):
166166
Version of Cylc used.
167167

168168
``CYLC_TEMPLATE_VARS``
169-
All variables set by the ``-s`` or ``--set-file`` options, or by a plugin.
169+
All variables set by the ``-s``, ``--set-file`` or ``--set-list`` options,
170+
or by a plugin.
170171

171172

172173
.. _CustomJinja2Filters:
@@ -262,10 +263,11 @@ Here's the result:
262263
Default Values and Template Variables
263264
-------------------------------------
264265

265-
You can provide template variables to Cylc in 3 ways:
266+
You can provide template variables to Cylc in 4 ways:
266267

267-
- Using the ``--set-file`` option.
268-
- Using the ``-s`` option.
268+
- Using the ``--set-file`` (``-S``) option.
269+
- Using the ``--set`` (``-s``) option.
270+
- Using the ``--set-list`` (``-z``) option.
269271
- `Using a plugin`_, such as :ref:`Cylc Rose`.
270272

271273
.. note::
@@ -274,15 +276,26 @@ You can provide template variables to Cylc in 3 ways:
274276
above list is used.
275277

276278

277-
The ``-s`` and ``--set-file`` Options
278-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
279+
The ``-s``, ``-z`` and ``--set-file`` Options
280+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
279281

280282
.. code-block:: console
281283
282284
$ # set the Jinja2 variable "answer" to 42
283285
$ cylc play <workflow-id> -s answer=42
284286
285-
Or for multiple variables defined in a file, use the ``--set-file`` option:
287+
A Python string-list is a valid value, but a lot to type, so ``--set-list``
288+
(``-z``) is provided as a convenience:
289+
290+
.. code-block:: console
291+
292+
# The set syntax
293+
$ cylc play <workflow-id> -s "answers=['mice', 'dolphins']"
294+
# ... can be shortened to:
295+
$ cylc play <workflow-id> -z answers=mice,dolphins
296+
297+
If you need to define a lot of variables, you can so in a file
298+
using the ``--set-file`` option:
286299

287300
.. code-block:: console
288301

0 commit comments

Comments
 (0)