mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ansible-doc snippet format changes
* ansible-doc -s is supposed to output a sample snippet of how you could add the module into a playbook. These changes update the style: * Use yaml mappings instead of key=value * Use the module name directly instead of action: modulename * Fixes a bug when displaying option descritpions which are yaml strings instead of lists. This fixes in code the bad formatting reported in #24201
This commit is contained in:
parent
2a7ce1059d
commit
e36d2f0bd0
1 changed files with 8 additions and 6 deletions
|
@ -262,23 +262,25 @@ class DocCLI(CLI):
|
|||
text = []
|
||||
desc = CLI.tty_ify(doc['short_description'])
|
||||
text.append("- name: %s" % (desc))
|
||||
text.append(" action: %s" % (doc['module']))
|
||||
text.append(" %s:" % (doc['module']))
|
||||
pad = 31
|
||||
subdent = " " * pad
|
||||
limit = display.columns - pad
|
||||
|
||||
for o in sorted(doc['options'].keys()):
|
||||
opt = doc['options'][o]
|
||||
desc = CLI.tty_ify(" ".join(opt['description']))
|
||||
if isinstance(opt['description'], string_types):
|
||||
desc = CLI.tty_ify(opt['description'])
|
||||
else:
|
||||
desc = CLI.tty_ify(" ".join(opt['description']))
|
||||
|
||||
required = opt.get('required', False)
|
||||
if not isinstance(required, bool):
|
||||
raise("Incorrect value for 'Required', a boolean is needed.: %s" % required)
|
||||
if required:
|
||||
s = o + "="
|
||||
else:
|
||||
s = o
|
||||
text.append(" %-20s # %s" % (s, textwrap.fill(desc, limit, subsequent_indent=subdent)))
|
||||
desc = "(required) %s" % desc
|
||||
o = '%s:' % o
|
||||
text.append(" %-20s # %s" % (o, textwrap.fill(desc, limit, subsequent_indent=subdent)))
|
||||
text.append('')
|
||||
|
||||
return "\n".join(text)
|
||||
|
|
Loading…
Reference in a new issue