Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible-doc now shows return value docs #10295

Merged
merged 1 commit into from
Feb 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/ansible-doc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ def get_man_text(doc):
text.append("%s\n" % (ex['code']))

if 'plainexamples' in doc and doc['plainexamples'] is not None:
text.append("EXAMPLES:")
text.append(doc['plainexamples'])
if 'returndocs' in doc and doc['returndocs'] is not None:
text.append("RETURN VALUES:")
text.append(doc['returndocs'])
text.append('')

return "\n".join(text)
Expand Down Expand Up @@ -299,7 +303,7 @@ def main():
continue

try:
doc, plainexamples = module_docs.get_docstring(filename)
doc, plainexamples, returndocs = module_docs.get_docstring(filename)
except:
traceback.print_exc()
sys.stderr.write("ERROR: module %s has a documentation error formatting or is missing documentation\n" % module)
Expand All @@ -317,6 +321,7 @@ def main():
doc['docuri'] = doc['module'].replace('_', '-')
doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d')
doc['plainexamples'] = plainexamples
doc['returndocs'] = returndocs

if options.show_snippet:
text += get_snippet_text(doc)
Expand Down
6 changes: 5 additions & 1 deletion lib/ansible/utils/module_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_docstring(filename, verbose=False):

doc = None
plainexamples = None
returndocs = None

try:
# Thank you, Habbie, for this bit of code :-)
Expand Down Expand Up @@ -89,10 +90,13 @@ def get_docstring(filename, verbose=False):

if 'EXAMPLES' in (t.id for t in child.targets):
plainexamples = child.value.s[1:] # Skip first empty line

if 'RETURN' in (t.id for t in child.targets):
returndocs = child.value.s[1:]
except:
traceback.print_exc() # temp
if verbose == True:
traceback.print_exc()
print "unable to parse %s" % filename
return doc, plainexamples
return doc, plainexamples, returndocs