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:
Toshio Kuratomi 2017-05-04 07:57:17 -07:00
parent 2a7ce1059d
commit e36d2f0bd0

View file

@ -262,23 +262,25 @@ class DocCLI(CLI):
text = [] text = []
desc = CLI.tty_ify(doc['short_description']) desc = CLI.tty_ify(doc['short_description'])
text.append("- name: %s" % (desc)) text.append("- name: %s" % (desc))
text.append(" action: %s" % (doc['module'])) text.append(" %s:" % (doc['module']))
pad = 31 pad = 31
subdent = " " * pad subdent = " " * pad
limit = display.columns - pad limit = display.columns - pad
for o in sorted(doc['options'].keys()): for o in sorted(doc['options'].keys()):
opt = doc['options'][o] 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) required = opt.get('required', False)
if not isinstance(required, bool): if not isinstance(required, bool):
raise("Incorrect value for 'Required', a boolean is needed.: %s" % required) raise("Incorrect value for 'Required', a boolean is needed.: %s" % required)
if required: if required:
s = o + "=" desc = "(required) %s" % desc
else: o = '%s:' % o
s = o text.append(" %-20s # %s" % (o, textwrap.fill(desc, limit, subsequent_indent=subdent)))
text.append(" %-20s # %s" % (s, textwrap.fill(desc, limit, subsequent_indent=subdent)))
text.append('') text.append('')
return "\n".join(text) return "\n".join(text)