Skip to content

Commit

Permalink
ansible-doc: export has_action when --json is used (ansible#72359)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
felixfontein authored Oct 30, 2020
1 parent 111589d commit 4fb336c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/ansible-doc-has_action.yml
Original file line number Diff line number Diff line change
@@ -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)."
29 changes: 15 additions & 14 deletions lib/ansible/cli/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def run(self):
# 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)
Expand Down Expand Up @@ -354,6 +354,19 @@ def _get_plugin_doc(plugin, plugin_type, loader, search_paths):
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']
Expand All @@ -369,18 +382,6 @@ def format_plugin_doc(plugin, plugin_type, doc, plainexamples, returndocs, metad
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:
Expand Down Expand Up @@ -658,7 +659,7 @@ def get_man_text(doc, collection_name='', plugin_type=''):
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):
Expand Down

0 comments on commit 4fb336c

Please sign in to comment.