summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fontein <felix@fontein.de>2020-12-07 16:45:10 +0100
committerGitHub <noreply@github.com>2020-12-07 09:45:10 -0600
commitf67b4e76954ecf44f15ee4f399ed85869f3ab32c (patch)
treebf7fd7912f747cc7bacb52c1595e5ec18cdb8a9f
parent74ec5ab6b5eb1f63ffd4e89e83eef7bd0e1674fe (diff)
downloadansible-f67b4e76954ecf44f15ee4f399ed85869f3ab32c.tar.gz
ansible-doc: export has_action when --json is used (#72359) (#72416)
* ansible-doc: export has_action when --json is used. * Remove docuri and now_data, which were not used resp. ignored in format_plugin_doc and the functions it calls anyway. * Add function _combine_plugin_doc. (cherry picked from commit 4fb336cef13e4b6e2b46a4d30e60d1d40cbbbd90)
-rw-r--r--changelogs/fragments/ansible-doc-has_action.yml2
-rw-r--r--lib/ansible/cli/doc.py28
2 files changed, 16 insertions, 14 deletions
diff --git a/changelogs/fragments/ansible-doc-has_action.yml b/changelogs/fragments/ansible-doc-has_action.yml
new file mode 100644
index 0000000000..f1ab97eb79
--- /dev/null
+++ b/changelogs/fragments/ansible-doc-has_action.yml
@@ -0,0 +1,2 @@
+minor_changes:
+- "ansible-doc - provide ``has_action`` field in JSON output for modules. That information is currently only available in the text view (https://github.com/ansible/ansible/pull/72359)."
diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py
index 0004c61295..72b6e7c409 100644
--- a/lib/ansible/cli/doc.py
+++ b/lib/ansible/cli/doc.py
@@ -209,8 +209,7 @@ class DocCLI(CLI):
# The doc section existed but was empty
continue
- plugin_docs[plugin] = {'doc': doc, 'examples': plainexamples,
- 'return': returndocs, 'metadata': metadata}
+ plugin_docs[plugin] = DocCLI._combine_plugin_doc(plugin, plugin_type, doc, plainexamples, returndocs, metadata)
if do_json:
# Some changes to how json docs are formatted
@@ -323,23 +322,24 @@ class DocCLI(CLI):
return doc, plainexamples, returndocs, metadata
@staticmethod
- def format_plugin_doc(plugin, plugin_type, doc, plainexamples, returndocs, metadata):
- # assign from other sections
- doc['plainexamples'] = plainexamples
- doc['returndocs'] = returndocs
- doc['metadata'] = metadata
-
+ def _combine_plugin_doc(plugin, plugin_type, doc, plainexamples, returndocs, metadata):
# generate extra data
if plugin_type == 'module':
# is there corresponding action plugin?
if plugin in action_loader:
- doc['action'] = True
+ doc['has_action'] = True
else:
- doc['action'] = False
+ doc['has_action'] = False
+
+ # return everything as one dictionary
+ return {'doc': doc, 'examples': plainexamples, 'return': returndocs, 'metadata': metadata}
- doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d')
- if 'docuri' in doc:
- doc['docuri'] = doc[plugin_type].replace('_', '-')
+ @staticmethod
+ def format_plugin_doc(plugin, plugin_type, doc, plainexamples, returndocs, metadata):
+ # assign from other sections
+ doc['plainexamples'] = plainexamples
+ doc['returndocs'] = returndocs
+ doc['metadata'] = metadata
if context.CLIARGS['show_snippet'] and plugin_type == 'module':
text = DocCLI.get_snippet_text(doc)
@@ -631,7 +631,7 @@ class DocCLI(CLI):
except Exception:
pass # FIXME: not suported by plugins
- if doc.pop('action', False):
+ if doc.pop('has_action', False):
text.append(" * note: %s\n" % "This module has a corresponding action plugin.")
if 'options' in doc and doc['options']: