diff --git a/bin/ansible-doc b/bin/ansible-doc index d5143f33a15..0ba84b9a305 100755 --- a/bin/ansible-doc +++ b/bin/ansible-doc @@ -34,6 +34,7 @@ import traceback MODULEDIR = C.DEFAULT_MODULE_PATH BLACKLIST_EXTS = ('.pyc', '.swp', '.bak', '~', '.rpm') +IGNORE_FILES = [ "COPYING", "CONTRIBUTING", "LICENSE", "README" ] _ITALIC = re.compile(r"I\(([^)]+)\)") _BOLD = re.compile(r"B\(([^)]+)\)") @@ -94,7 +95,7 @@ def get_man_text(doc): desc = " ".join(doc['description']) text.append("%s\n" % textwrap.fill(tty_ify(desc), initial_indent=" ", subsequent_indent=" ")) - + if 'option_keys' in doc and len(doc['option_keys']) > 0: text.append("Options (= is mandatory):\n") @@ -164,7 +165,11 @@ def get_snippet_text(doc): return "\n".join(text) def get_module_list_text(module_list): + columns = max(60, int(os.popen('stty size', 'r').read().split()[1])) + displace = max(len(x) for x in module_list) + linelimit = columns - displace - 5 text = [] + deprecated = [] for module in sorted(set(module_list)): if module in module_docs.BLACKLIST_MODULES: @@ -181,15 +186,45 @@ def get_module_list_text(module_list): try: doc, plainexamples = module_docs.get_docstring(filename) - desc = tty_ify(doc.get('short_description', '?')) - if len(desc) > 55: - desc = desc + '...' - text.append("%-20s %-60.60s" % (module, desc)) + desc = tty_ify(doc.get('short_description', '?')).strip() + if len(desc) > linelimit: + desc = desc[:linelimit] + '...' + + if module.startswith('_'): # Handle deprecated + deprecated.append("%-*s %-*.*s" % (displace, module[1:], linelimit, len(desc), desc)) + else: + text.append("%-*s %-*.*s" % (displace, module, linelimit, len(desc), desc)) except: traceback.print_exc() sys.stderr.write("ERROR: module %s has a documentation error formatting or is missing documentation\n" % module) + + if len(deprecated) > 0: + text.append("\nDEPRECATED:") + text.extend(deprecated) return "\n".join(text) +def find_modules(path, module_list): + + if os.path.isdir(path): + for module in os.listdir(path): + if module.startswith('.'): + continue + elif os.path.isdir(module): + find_modules(module, module_list) + elif any(module.endswith(x) for x in BLACKLIST_EXTS): + continue + elif module.startswith('__'): + continue + elif module in IGNORE_FILES: + continue + elif module.startswith('_'): + fullpath = '/'.join([path,module]) + if os.path.islink(fullpath): # avoids aliases + continue + + module = os.path.splitext(module)[0] # removes the extension + module_list.append(module) + def main(): p = optparse.OptionParser( @@ -222,23 +257,18 @@ def main(): utils.plugins.module_finder.add_directory(i) if options.list_dir: - # list all modules + # list modules paths = utils.plugins.module_finder._get_paths() module_list = [] for path in paths: - # os.system("ls -C %s" % (path)) - if os.path.isdir(path): - for module in os.listdir(path): - if any(module.endswith(x) for x in BLACKLIST_EXTS): - continue - module_list.append(module) + find_modules(path, module_list) pager(get_module_list_text(module_list)) sys.exit() if len(args) == 0: p.print_help() - + def print_paths(finder): ''' Returns a string suitable for printing of the search path ''' @@ -248,14 +278,13 @@ def main(): if i not in ret: ret.append(i) return os.pathsep.join(ret) - + text = '' for module in args: filename = utils.plugins.module_finder.find_plugin(module) if filename is None: - sys.stderr.write("module %s not found in %s\n" % (module, - print_paths(utils.plugins.module_finder))) + sys.stderr.write("module %s not found in %s\n" % (module, print_paths(utils.plugins.module_finder))) continue if any(filename.endswith(x) for x in BLACKLIST_EXTS): diff --git a/docsite/rst/developing_modules.rst b/docsite/rst/developing_modules.rst index 608ac7185bc..4a331626db1 100644 --- a/docsite/rst/developing_modules.rst +++ b/docsite/rst/developing_modules.rst @@ -465,6 +465,23 @@ a github pull request to the `extras