diff options
author | Felix Fontein <felix@fontein.de> | 2020-06-08 17:51:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-08 17:51:33 +0200 |
commit | 840d3a9dd7d1233ab55aa9516fc9b44e4c865a81 (patch) | |
tree | 62f6d6ad1aa045b02a62853c0b1d33b5750b4116 /lib | |
parent | Update developing_modules_best_practices.rst (#69937) (diff) | |
download | ansible-840d3a9dd7d1233ab55aa9516fc9b44e4c865a81.tar.xz ansible-840d3a9dd7d1233ab55aa9516fc9b44e4c865a81.zip |
ansible-doc: properly handle suboptions (#69795)
* Specifically handle suboptions, contains, etc in ansible-doc.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansible/cli/doc.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index dec582fb98..fbf0223bac 100644 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -503,7 +503,7 @@ class DocCLI(CLI): Dumper=AnsibleDumper).split('\n')])) @staticmethod - def add_fields(text, fields, limit, opt_indent): + def add_fields(text, fields, limit, opt_indent, base_indent=''): for o in sorted(fields): opt = fields[o] @@ -516,7 +516,7 @@ class DocCLI(CLI): else: opt_leadin = "-" - text.append("%s %s" % (opt_leadin, o)) + text.append("%s%s %s" % (base_indent, opt_leadin, o)) if isinstance(opt['description'], list): for entry_idx, entry in enumerate(opt['description'], 1): @@ -546,13 +546,10 @@ class DocCLI(CLI): text.append(textwrap.fill(DocCLI.tty_ify(aliases + choices + default), limit, initial_indent=opt_indent, subsequent_indent=opt_indent)) - if 'options' in opt: - text.append("%soptions:\n" % opt_indent) - DocCLI.add_fields(text, opt.pop('options'), limit, opt_indent + opt_indent) - - if 'spec' in opt: - text.append("%sspec:\n" % opt_indent) - DocCLI.add_fields(text, opt.pop('spec'), limit, opt_indent + opt_indent) + suboptions = [] + for subkey in ('options', 'suboptions', 'contains', 'spec'): + if subkey in opt: + suboptions.append((subkey, opt.pop(subkey))) conf = {} for config in ('env', 'ini', 'yaml', 'vars', 'keywords'): @@ -578,7 +575,13 @@ class DocCLI(CLI): text.append(DocCLI.tty_ify('%s%s: %s' % (opt_indent, k, ', '.join(opt[k])))) else: text.append(DocCLI._dump_yaml({k: opt[k]}, opt_indent)) - text.append('') + + for subkey, subdata in suboptions: + text.append('') + text.append("%s%s:\n" % (opt_indent, subkey.upper())) + DocCLI.add_fields(text, subdata, limit, opt_indent + ' ', opt_indent) + if not suboptions: + text.append('') @staticmethod def get_man_text(doc): |