You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/docs/templates/cli_rst.j2

162 lines
3.4 KiB
Plaintext

:source: {{ cli }}.py
{% set name = cli_name -%}
{% set name_slug = cli_name -%}
.. _{{name}}:
{% set name_len = name|length + 0-%}
{{ '=' * name_len }}
{{name}}
{{ '=' * name_len }}
:strong:`{{short_desc|default('')}}`
.. contents::
:local:
:depth: {{content_depth}}
.. program:: {{cli_name}}
Synopsis
========
.. code-block:: bash
{{ usage|replace('%prog', cli_name) }}
Description
===========
{{ long_desc|default('', True) }}
{% if options %}
Common Options
==============
{% for option in options|sort(attribute='options') if option.options %}
.. option:: {% for switch in option['options'] %}{{switch}}{% if option['arg'] %} <{{option['arg']}}>{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}
{{ option['desc'] }}
{% endfor %}
{% endif %}
{% if arguments %}
ARGUMENTS
=========
.. program:: {{cli_name}}
{% for arg in arguments %}
.. option:: {{ arg }}
{{ (arguments[arg]|default(' '))}}
{% endfor %}
{% endif %}
{% if actions %}
Actions
=======
{% for action in actions %}
.. program:: {{cli_name}} {{action}}
.. _{{cli_name|replace('-','_')}}_{{action}}:
{{ action}}
{{ '-' * action|length}}
{{ (actions[action]['desc']|default(' '))}}
{% if actions[action]['options'] %}
{% for option in actions[action]['options']|sort(attribute='options') %}
.. option:: {% for switch in option['options'] if switch in actions[action]['option_names'] %}{{switch}} {% if option['arg'] %} <{{option['arg']}}>{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}
{{ (option['desc']) }}
{% endfor %}
{% endif %}
{% for sub_action in actions[action]['actions'] %}
.. program:: {{cli_name}} {{action}} {{sub_action}}
.. _{{cli_name|replace('-','_')}}_{{action}}_{{sub_action}}:
{{ action + " " + sub_action }}
{{ '+' * (action|length + sub_action|length + 1) }}
{{ (actions[action]['actions'][sub_action]['desc']|default(' '))}}
{% if actions[action]['actions'][sub_action]['options'] %}
{% for option in actions[action]['actions'][sub_action]['options']|sort(attribute='options') %}
.. option:: {% for switch in option['options'] if switch in actions[action]['actions'][sub_action]['option_names'] %}{{switch}} {% if option['arg'] %} <{{option['arg']}}>{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}
{{ (option['desc']) }}
{% endfor %}
{% endif %}
{% endfor %}
{% endfor %}
.. program:: {{cli_name}}
{% endif %}
Environment
===========
The following environment variables may be specified.
{% if inventory %}
:envvar:`ANSIBLE_INVENTORY` -- Override the default ansible inventory file
{% endif %}
{% if library %}
:envvar:`ANSIBLE_LIBRARY` -- Override the default ansible module library path
{% endif %}
:envvar:`ANSIBLE_CONFIG` -- Override the default ansible config file
Many more are available for most options in ansible.cfg
Files
=====
{% if inventory %}
:file:`/etc/ansible/hosts` -- Default inventory file
{% endif %}
:file:`/etc/ansible/ansible.cfg` -- Config file, used if present
:file:`~/.ansible.cfg` -- User config file, overrides the default config if present
Author
======
Ansible was originally written by Michael DeHaan.
See the `AUTHORS` file for a complete list of contributors.
License
=======
Ansible is released under the terms of the GPLv3+ License.
See also
========
Fix misrendered sections in manpage generation This change fixes bugs in the manpage generator that existed since it was first added. It exposes CLI `ARGUMENTS` value to manpage templates. Before this change, the code contained a typo, causing the `for`-loop iterate over individual characters of the `'ARGUMENTS'` string rather than iterating over a tuple. A missing comma was at fault. The updated code gets rid of the `for`-loop and conditionals since it seems to have been a premature complexity increase and no other things than `'ARGUMENTS'` were ever added into the broken iterable. The functional change is that `arguments` is now always present in the Jinja2 context, unlike being missing sometimes because of the previous design (not that it was ever present, because of the bug! sigh...) The Jinja2 templates perform an `{% if arguments %}` check, letting the template engine silently ignore the missing variable. The clause was always falsy, meaning that the arguments section was not included in the manpages for at least the last 6 years. With this fix, it will be. This patch also deduplicates calling `opt_doc_list` @ generate_man. It was called late in the execution, more times than necessary. This patch makes sure it happens once by putting it at the top of the scope. It fixes rendering library and inventory in manpages. The corresponding Jinja2 templates have blocks wrapped with conditionals like `{% if inventory %}` and `{% if library %}` but said variables were never injected into the context, nor were they even deduced on the Python side of the generator. This means that the conditional clauses were always falsy, never showing the portions of the manpages. The Python script has hints for how the `inventory` variable was to be calculated, which is confirmed through the Git paleontology efforts. The block of code that references to the `inventory` bit was incorrectly checking a variable with a list of nested objects for the presence of a string which was never going to work. This patch fixes this check by verifying the CLI flag against the correct variable containing a list of options and exposes it to the Jinja2 templates. It also exposes the `library` variable in a similar way. The block displaying other binaries in Sphinx CLI docs has been synchronized with the manpage template. Previously, the current binary was displayed also. This patch gets rid of the unwanted trailing comma there too. Finally, the CLI executables list in the manpage template now reuses the same variable as the RST template that doesn't need any post-processing in Jinja2. Before, it was already used in the RST template so this patch aligns both templates to use the same logic as they got out-of-sync over time. PR #80450.
1 year ago
{% for other in cli_bin_name_list|sort %}{% if other != cli_name %}:manpage:`{{other}}(1)`{% if not loop.last %}, {% endif %}{% endif %}{% endfor %}