diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2018-05-30 15:32:25 -0400 |
---|---|---|
committer | Matt Davis <nitzmahone@users.noreply.github.com> | 2018-05-30 12:32:25 -0700 |
commit | f7f8d2b13304aed95c0b69f999872709d27b6b22 (patch) | |
tree | 1ea42b8a13ad0a14c49b3de670310d9f4a22e683 | |
parent | b1c4d6310da71a1aa7532c99470b9b41656ee1e9 (diff) | |
download | ansible-f7f8d2b13304aed95c0b69f999872709d27b6b22.tar.gz |
add keywords handling to ansible-doc (#40908)
also add check for sequence of string types before we force a join
(cherry picked from commit 73b98926052ee62b7df2c91916b6961e77ff74dc)
-rw-r--r-- | changelogs/fragments/adoc_keys.yml | 2 | ||||
-rw-r--r-- | lib/ansible/cli/doc.py | 14 |
2 files changed, 10 insertions, 6 deletions
diff --git a/changelogs/fragments/adoc_keys.yml b/changelogs/fragments/adoc_keys.yml new file mode 100644 index 0000000000..aa9e1d8d9e --- /dev/null +++ b/changelogs/fragments/adoc_keys.yml @@ -0,0 +1,2 @@ +- bugfixes: + - allow ansible-doc to handle 'keywords' configuration entries https://github.com/ansible/ansible/pull/40620 diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index a0f17d63a5..f445551026 100644 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -22,6 +22,8 @@ import textwrap import traceback import yaml +from collections import Sequence + from ansible import constants as C from ansible.cli import CLI from ansible.errors import AnsibleError, AnsibleOptionsError @@ -160,7 +162,7 @@ class DocCLI(CLI): try: doc, plainexamples, returndocs, metadata = get_docstring(filename, fragment_loader, verbose=(self.options.verbosity > 0)) - except: + except Exception: display.vvv(traceback.format_exc()) display.error("%s %s has a documentation error formatting or is missing documentation." % (plugin_type, plugin), wrap_text=False) continue @@ -256,7 +258,7 @@ class DocCLI(CLI): doc = None try: doc, plainexamples, returndocs, metadata = get_docstring(filename, fragment_loader) - except: + except Exception: display.warning("%s has a documentation formatting error" % plugin) if not doc or not isinstance(doc, dict): @@ -395,7 +397,7 @@ class DocCLI(CLI): self.add_fields(text, opt.pop('spec'), limit, opt_indent + opt_indent) conf = {} - for config in ('env', 'ini', 'yaml', 'vars'): + for config in ('env', 'ini', 'yaml', 'vars', 'keywords'): if config in opt and opt[config]: conf[config] = opt.pop(config) for ignore in self.IGNORE: @@ -411,7 +413,7 @@ class DocCLI(CLI): continue if isinstance(opt[k], string_types): text.append('%s%s: %s' % (opt_indent, k, textwrap.fill(CLI.tty_ify(opt[k]), limit - (len(k) + 2), subsequent_indent=opt_indent))) - elif isinstance(opt[k], (list, tuple)): + elif isinstance(opt[k], (Sequence)) and all(isinstance(x, string_types) for x in opt[k]): text.append(CLI.tty_ify('%s%s: %s' % (opt_indent, k, ', '.join(opt[k])))) else: text.append(self._dump_yaml({k: opt[k]}, opt_indent)) @@ -476,7 +478,7 @@ class DocCLI(CLI): support_block = self.get_support_block(doc) if support_block: text.extend(support_block) - except: + except Exception: pass # FIXME: not suported by plugins if doc.pop('action', False): @@ -532,7 +534,7 @@ class DocCLI(CLI): if metadata_block: text.extend(metadata_block) text.append('') - except: + except Exception: pass # metadata is optional return "\n".join(text) |