Skip to content

Commit 356dc95

Browse files
Klaus Frankfelixfontein
Klaus Frank
andauthored
Add param ordering note to plugins page. (#101)
* Add param ordering note to plugins. Add a note to every filter, test, and lookup to list positional parameters before keyword ones. * review suggestions * Remove whitespace handling and lookup filter * Adjust/fix examples, also support lookups better. * Update baseline for tests. * Adjust changelog fragment. * Lookups have no positional parameters. (They have terms.) * Support lookup terms. * Be more explicit. * Update baseline. --------- Co-authored-by: Felix Fontein <[email protected]>
1 parent 57f59bc commit 356dc95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+107
-74
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- Add a note about the ordering of positional and named parameter to the plugin page. Also mention positional and keyword parameters for lookups (https://github.com/ansible-community/antsibull-docs/pull/101).

src/antsibull_docs/data/docsite/plugin.rst.j2

+35-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
{% from 'macros/returnvalues.rst.j2' import in_rst as return_docs_rst with context %}
1111
{% from 'macros/returnvalues.rst.j2' import in_html as return_docs_html with context %}
1212
{% from 'macros/version_added.rst.j2' import version_added_rst %}
13+
{% set has_positional_parameters = false %}
14+
{% set has_keyword_parameters = false %}
1315
.. Document meta
1416

1517
:orphan:
@@ -196,6 +198,7 @@ The below requirements are needed on the local controller node that executes thi
196198

197199
{% if doc['options']['_terms'] and plugin_type in ['lookup'] %}
198200
{% set options_to_skip = options_to_skip + ['_terms'] %}
201+
{% set has_positional_parameters = true %}
199202

200203
.. Terms
201204

@@ -220,7 +223,7 @@ Input
220223

221224
{% if plugin_type == 'filter' %}
222225
This describes the input of the filter, the value before ``| @{plugin_name}@``.
223-
{% else %}
226+
{% elif plugin_type == 'test' %}
224227
This describes the input of the test, the value before ``is @{plugin_name}@`` or ``is not @{plugin_name}@``.
225228
{% endif %}
226229

@@ -232,18 +235,20 @@ This describes the input of the test, the value before ``is @{plugin_name}@`` or
232235

233236
{% endif %}
234237

235-
{% if doc['positional'] and plugin_type in ['lookup', 'filter', 'test'] and doc['positional'] != ['_input'] %}
238+
{% if doc['positional'] and plugin_type in ['filter', 'test'] and doc['positional'] != ['_input'] %}
239+
{% set has_positional_parameters = true %}
236240
{% set options_to_skip = options_to_skip + doc['positional'] %}
237241

238242
.. Positional
239243

240244
Positional parameters
241245
---------------------
242246

247+
This describes positional parameters of the @{plugin_type}@. These are the values ``positional1``, ``positional2`` and so on in the following
243248
{% if plugin_type == 'filter' %}
244-
This describes positional parameters of the filter. These are the values ``positional1``, ``positional2`` and so on in the following example: ``input | @{plugin_name}@(positional1, positional2, ...)``.
249+
example: ``input | @{plugin_name}@(positional1, positional2, ...)``
245250
{% elif plugin_type == 'test' %}
246-
This describes positional parameters of the test. These are the values ``positional1``, ``positional2`` and so on in the following examples: ``input is @{plugin_name}@(positional1, positional2, ...)`` and ``input is not @{plugin_name}@(positional1, positional2, ...)``.
251+
examples: ``input is @{plugin_name}@(positional1, positional2, ...)`` and ``input is not @{plugin_name}@(positional1, positional2, ...)``
247252
{% endif %}
248253

249254
{% if use_html_blobs %}
@@ -257,21 +262,25 @@ This describes positional parameters of the test. These are the values ``positio
257262
.. Options
258263

259264
{% if doc['options'] | remove_options_from_list(options_to_skip) -%}
265+
{% set has_keyword_parameters = true -%}
260266

261-
{% if plugin_type in ['filter', 'test'] %}
267+
{% if plugin_type in ['lookup', 'filter', 'test'] %}
262268
Keyword parameters
263269
------------------
270+
271+
This describes keyword parameters of the @{plugin_type}@. These are the values ``key1=value1``, ``key2=value2`` and so on in the following
272+
{% if plugin_type == 'filter' %}
273+
example: ``input | @{plugin_name}@(key1=value1, key2=value2, ...)``
274+
{% elif plugin_type == 'test' %}
275+
examples: ``input is @{plugin_name}@(key1=value1, key2=value2, ...)`` and ``input is not @{plugin_name}@(key1=value1, key2=value2, ...)``
276+
{% elif plugin_type == 'lookup' %}
277+
examples: ``lookup('@{plugin_name}@', key1=value1, key2=value2, ...)`` and ``query('@{plugin_name}@', key1=value1, key2=value2, ...)``
278+
{% endif %}
264279
{% else %}
265280
Parameters
266281
----------
267282
{% endif %}
268283

269-
{% if plugin_type == 'filter' %}
270-
This describes keyword parameters of the filter. These are the values ``key1=value1``, ``key2=value2`` and so on in the following example: ``input | @{plugin_name}@(key1=value1, key2=value2, ...)``.
271-
{% elif plugin_type == 'test' %}
272-
This describes keyword parameters of the test. These are the values ``key1=value1``, ``key2=value2`` and so on in the following examples: ``input is @{plugin_name}@(key1=value1, key2=value2, ...)`` and ``input is not @{plugin_name}@(key1=value1, key2=value2, ...)``.
273-
{% endif %}
274-
275284
{% if use_html_blobs %}
276285
@{ parameters_html(doc['options'] | remove_options_from_list(options_to_skip) | dictsort, suboption_key='suboptions') }@
277286
{% else %}
@@ -291,14 +300,26 @@ Attributes
291300

292301
.. Notes
293302

294-
{% if doc['notes'] -%}
303+
{% if doc['notes'] or (has_positional_parameters and has_keyword_parameters) -%}
295304
Notes
296305
-----
297306

298307
.. note::
299-
{% for note in doc['notes'] %}
308+
{% if has_positional_parameters and has_keyword_parameters %}
309+
- When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters:
310+
{% if plugin_type == 'filter' %}
311+
``input | @{plugin_name}@(positional1, positional2, key1=value1, key2=value2)``
312+
{% elif plugin_type == 'test' %}
313+
``input is @{plugin_name}@(positional1, positional2, key1=value1, key2=value2)`` and ``input is not @{plugin_name}@(positional1, positional2, key1=value1, key2=value2)``
314+
{% elif plugin_type == 'lookup' %}
315+
``lookup('@{plugin_name}@', term1, term2, key1=value1, key2=value2)`` and ``query('@{plugin_name}@', term1, term2, key1=value1, key2=value2)``
316+
{% endif %}
317+
{% endif %}
318+
{% if doc['notes'] %}
319+
{% for note in doc['notes'] %}
300320
- @{ note | rst_ify | indent(width=5) }@
301-
{% endfor %}
321+
{% endfor %}
322+
{% endif %}
302323
{% endif %}
303324

304325
.. Seealso

tests/functional/baseline-default/collections/ns2/col/foo_become.rst

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ Synopsis
8383
Parameters
8484
----------
8585

86-
8786
.. rst-class:: ansible-option-table
8887

8988
.. list-table::

tests/functional/baseline-default/collections/ns2/col/foo_cache.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-default/collections/ns2/col/foo_callback.rst

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ Synopsis
9191
Parameters
9292
----------
9393

94-
9594
.. rst-class:: ansible-option-table
9695

9796
.. list-table::

tests/functional/baseline-default/collections/ns2/col/foo_connection.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-default/collections/ns2/col/foo_filter.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ This describes the input of the filter, the value before ``| ns2.col.foo``.
141141
Keyword parameters
142142
------------------
143143

144-
This describes keyword parameters of the filter. These are the values ``key1=value1``, ``key2=value2`` and so on in the following example: ``input | ns2.col.foo(key1=value1, key2=value2, ...)``.
144+
This describes keyword parameters of the filter. These are the values ``key1=value1``, ``key2=value2`` and so on in the following
145+
example: ``input | ns2.col.foo(key1=value1, key2=value2, ...)``
145146

146147
.. rst-class:: ansible-option-table
147148

tests/functional/baseline-default/collections/ns2/col/foo_inventory.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-default/collections/ns2/col/foo_lookup.rst

+10-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ Terms
137137

138138
.. Options
139139
140-
Parameters
141-
----------
140+
Keyword parameters
141+
------------------
142142

143+
This describes keyword parameters of the lookup. These are the values ``key1=value1``, ``key2=value2`` and so on in the following
144+
examples: ``lookup('ns2.col.foo', key1=value1, key2=value2, ...)`` and ``query('ns2.col.foo', key1=value1, key2=value2, ...)``
143145

144146
.. rst-class:: ansible-option-table
145147

@@ -194,6 +196,12 @@ Parameters
194196
195197
.. Notes
196198
199+
Notes
200+
-----
201+
202+
.. note::
203+
- When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters:
204+
``lookup('ns2.col.foo', term1, term2, key1=value1, key2=value2)`` and ``query('ns2.col.foo', term1, term2, key1=value1, key2=value2)``
197205

198206
.. Seealso
199207

tests/functional/baseline-default/collections/ns2/col/foo_module.rst

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ The below requirements are needed on the host that executes this module.
9696
Parameters
9797
----------
9898

99-
10099
.. rst-class:: ansible-option-table
101100

102101
.. list-table::

tests/functional/baseline-default/collections/ns2/col/foo_shell.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-default/collections/ns2/col/foo_test.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ This describes the input of the test, the value before ``is ns2.col.foo`` or ``i
138138
Keyword parameters
139139
------------------
140140

141-
This describes keyword parameters of the test. These are the values ``key1=value1``, ``key2=value2`` and so on in the following examples: ``input is ns2.col.foo(key1=value1, key2=value2, ...)`` and ``input is not ns2.col.foo(key1=value1, key2=value2, ...)``.
141+
This describes keyword parameters of the test. These are the values ``key1=value1``, ``key2=value2`` and so on in the following
142+
examples: ``input is ns2.col.foo(key1=value1, key2=value2, ...)`` and ``input is not ns2.col.foo(key1=value1, key2=value2, ...)``
142143

143144
.. rst-class:: ansible-option-table
144145

tests/functional/baseline-default/collections/ns2/col/foo_vars.rst

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ The below requirements are needed on the local controller node that executes thi
9696
Parameters
9797
----------
9898

99-
10099
.. rst-class:: ansible-option-table
101100

102101
.. list-table::

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_become.rst

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ Synopsis
8383
Parameters
8484
----------
8585

86-
8786
.. rst-class:: ansible-option-table
8887

8988
.. list-table::

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_cache.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_callback.rst

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ Synopsis
9191
Parameters
9292
----------
9393

94-
9594
.. rst-class:: ansible-option-table
9695

9796
.. list-table::

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_connection.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_filter.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ This describes the input of the filter, the value before ``| ns2.col.foo``.
141141
Keyword parameters
142142
------------------
143143

144-
This describes keyword parameters of the filter. These are the values ``key1=value1``, ``key2=value2`` and so on in the following example: ``input | ns2.col.foo(key1=value1, key2=value2, ...)``.
144+
This describes keyword parameters of the filter. These are the values ``key1=value1``, ``key2=value2`` and so on in the following
145+
example: ``input | ns2.col.foo(key1=value1, key2=value2, ...)``
145146

146147
.. rst-class:: ansible-option-table
147148

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_inventory.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_lookup.rst

+10-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ Terms
137137

138138
.. Options
139139
140-
Parameters
141-
----------
140+
Keyword parameters
141+
------------------
142142

143+
This describes keyword parameters of the lookup. These are the values ``key1=value1``, ``key2=value2`` and so on in the following
144+
examples: ``lookup('ns2.col.foo', key1=value1, key2=value2, ...)`` and ``query('ns2.col.foo', key1=value1, key2=value2, ...)``
143145

144146
.. rst-class:: ansible-option-table
145147

@@ -194,6 +196,12 @@ Parameters
194196
195197
.. Notes
196198
199+
Notes
200+
-----
201+
202+
.. note::
203+
- When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters:
204+
``lookup('ns2.col.foo', term1, term2, key1=value1, key2=value2)`` and ``query('ns2.col.foo', term1, term2, key1=value1, key2=value2)``
197205

198206
.. Seealso
199207

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_module.rst

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ The below requirements are needed on the host that executes this module.
9696
Parameters
9797
----------
9898

99-
10099
.. rst-class:: ansible-option-table
101100

102101
.. list-table::

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_shell.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_test.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ This describes the input of the test, the value before ``is ns2.col.foo`` or ``i
138138
Keyword parameters
139139
------------------
140140

141-
This describes keyword parameters of the test. These are the values ``key1=value1``, ``key2=value2`` and so on in the following examples: ``input is ns2.col.foo(key1=value1, key2=value2, ...)`` and ``input is not ns2.col.foo(key1=value1, key2=value2, ...)``.
141+
This describes keyword parameters of the test. These are the values ``key1=value1``, ``key2=value2`` and so on in the following
142+
examples: ``input is ns2.col.foo(key1=value1, key2=value2, ...)`` and ``input is not ns2.col.foo(key1=value1, key2=value2, ...)``
142143

143144
.. rst-class:: ansible-option-table
144145

tests/functional/baseline-no-breadcrumbs/collections/ns2/col/foo_vars.rst

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ The below requirements are needed on the local controller node that executes thi
9696
Parameters
9797
----------
9898

99-
10099
.. rst-class:: ansible-option-table
101100

102101
.. list-table::

tests/functional/baseline-no-indexes/collections/ns2/col/foo_become.rst

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ Synopsis
8383
Parameters
8484
----------
8585

86-
8786
.. rst-class:: ansible-option-table
8887

8988
.. list-table::

tests/functional/baseline-no-indexes/collections/ns2/col/foo_cache.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-no-indexes/collections/ns2/col/foo_callback.rst

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ Synopsis
9191
Parameters
9292
----------
9393

94-
9594
.. rst-class:: ansible-option-table
9695

9796
.. list-table::

tests/functional/baseline-no-indexes/collections/ns2/col/foo_connection.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

tests/functional/baseline-no-indexes/collections/ns2/col/foo_filter.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ This describes the input of the filter, the value before ``| ns2.col.foo``.
141141
Keyword parameters
142142
------------------
143143

144-
This describes keyword parameters of the filter. These are the values ``key1=value1``, ``key2=value2`` and so on in the following example: ``input | ns2.col.foo(key1=value1, key2=value2, ...)``.
144+
This describes keyword parameters of the filter. These are the values ``key1=value1``, ``key2=value2`` and so on in the following
145+
example: ``input | ns2.col.foo(key1=value1, key2=value2, ...)``
145146

146147
.. rst-class:: ansible-option-table
147148

tests/functional/baseline-no-indexes/collections/ns2/col/foo_inventory.rst

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ Synopsis
8585
Parameters
8686
----------
8787

88-
8988
.. rst-class:: ansible-option-table
9089

9190
.. list-table::

0 commit comments

Comments
 (0)