From 42da4807214cd609fd3c1800ab245c025ae044cd Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 7 Dec 2020 23:59:33 +0100 Subject: [PATCH] ansible-doc: export has_action when --json is used (#72359) (#72414) * 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) --- .../fragments/ansible-doc-has_action.yml | 2 ++ lib/ansible/cli/doc.py | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 changelogs/fragments/ansible-doc-has_action.yml diff --git a/changelogs/fragments/ansible-doc-has_action.yml b/changelogs/fragments/ansible-doc-has_action.yml new file mode 100644 index 00000000000..f1ab97eb79d --- /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 061b406853a..41baa796653 100644 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -259,7 +259,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: jdump(plugin_docs) @@ -354,6 +354,19 @@ class DocCLI(CLI): doc['collection'] = collection_name return doc, plainexamples, returndocs, metadata + @staticmethod + 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['has_action'] = True + else: + doc['has_action'] = False + + # return everything as one dictionary + return {'doc': doc, 'examples': plainexamples, 'return': returndocs, 'metadata': metadata} + @staticmethod def format_plugin_doc(plugin, plugin_type, doc, plainexamples, returndocs, metadata): collection_name = doc['collection'] @@ -369,18 +382,6 @@ class DocCLI(CLI): doc['returndocs'] = returndocs doc['metadata'] = metadata - # generate extra data - if plugin_type == 'module': - # is there corresponding action plugin? - if plugin in action_loader: - doc['action'] = True - else: - doc['action'] = False - - doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d') - if 'docuri' in doc: - doc['docuri'] = doc[plugin_type].replace('_', '-') - if context.CLIARGS['show_snippet'] and plugin_type == 'module': text = DocCLI.get_snippet_text(doc) else: @@ -658,7 +659,7 @@ class DocCLI(CLI): text.append("%s" % doc.pop('deprecated')) text.append("\n") - if doc.pop('action', False): + if doc.pop('has_action', False): text.append(" * note: %s\n" % "This module has a corresponding action plugin.") if doc.get('options', False):