1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #10295 from bcoca/show_return_val_docs

ansible-doc now shows return value docs
This commit is contained in:
Brian Coca 2015-02-19 18:00:06 -05:00
commit e842f8fab9
2 changed files with 11 additions and 2 deletions

View file

@ -141,7 +141,11 @@ def get_man_text(doc):
text.append("%s\n" % (ex['code'])) text.append("%s\n" % (ex['code']))
if 'plainexamples' in doc and doc['plainexamples'] is not None: if 'plainexamples' in doc and doc['plainexamples'] is not None:
text.append("EXAMPLES:")
text.append(doc['plainexamples']) text.append(doc['plainexamples'])
if 'returndocs' in doc and doc['returndocs'] is not None:
text.append("RETURN VALUES:")
text.append(doc['returndocs'])
text.append('') text.append('')
return "\n".join(text) return "\n".join(text)
@ -299,7 +303,7 @@ def main():
continue continue
try: try:
doc, plainexamples = module_docs.get_docstring(filename) doc, plainexamples, returndocs = module_docs.get_docstring(filename)
except: except:
traceback.print_exc() traceback.print_exc()
sys.stderr.write("ERROR: module %s has a documentation error formatting or is missing documentation\n" % module) sys.stderr.write("ERROR: module %s has a documentation error formatting or is missing documentation\n" % module)
@ -317,6 +321,7 @@ def main():
doc['docuri'] = doc['module'].replace('_', '-') doc['docuri'] = doc['module'].replace('_', '-')
doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d') doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d')
doc['plainexamples'] = plainexamples doc['plainexamples'] = plainexamples
doc['returndocs'] = returndocs
if options.show_snippet: if options.show_snippet:
text += get_snippet_text(doc) text += get_snippet_text(doc)

View file

@ -44,6 +44,7 @@ def get_docstring(filename, verbose=False):
doc = None doc = None
plainexamples = None plainexamples = None
returndocs = None
try: try:
# Thank you, Habbie, for this bit of code :-) # Thank you, Habbie, for this bit of code :-)
@ -89,10 +90,13 @@ def get_docstring(filename, verbose=False):
if 'EXAMPLES' in (t.id for t in child.targets): if 'EXAMPLES' in (t.id for t in child.targets):
plainexamples = child.value.s[1:] # Skip first empty line 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: except:
traceback.print_exc() # temp traceback.print_exc() # temp
if verbose == True: if verbose == True:
traceback.print_exc() traceback.print_exc()
print "unable to parse %s" % filename print "unable to parse %s" % filename
return doc, plainexamples return doc, plainexamples, returndocs