diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index d8e4dec4f0..570c02e5b8 100644 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -52,12 +52,14 @@ class DocCLI(CLI): def parse(self): self.parser = CLI.base_parser( - usage='usage: %prog [-l|-s] [options] [-t 1: - raise AnsibleOptionsError("Only one of -l, -s or -a can be used at the same time.") + if [self.options.all_plugins, self.options.list_dir, self.options.list_files, self.options.show_snippet].count(True) > 1: + raise AnsibleOptionsError("Only one of -l, -F, -s or -a can be used at the same time.") display.verbosity = self.options.verbosity @@ -109,6 +111,16 @@ class DocCLI(CLI): search_paths = DocCLI.print_paths(loader) loader._paths = None # reset so we can use subdirs below + # list plugins names and filepath for type + if self.options.list_files: + paths = loader._get_paths() + for path in paths: + self.find_plugins(path, plugin_type) + + list_text = self.get_plugin_list_filenames(loader) + self.pager(list_text) + return 0 + # list plugins for type if self.options.list_dir: paths = loader._get_paths() @@ -264,6 +276,32 @@ class DocCLI(CLI): text.extend(deprecated) return "\n".join(text) + def get_plugin_list_filenames(self, loader): + columns = display.columns + displace = max(len(x) for x in self.plugin_list) + linelimit = columns - displace - 5 + text = [] + + for plugin in sorted(self.plugin_list): + + try: + # if the module lives in a non-python file (eg, win_X.ps1), require the corresponding python file for docs + filename = loader.find_plugin(plugin, mod_type='.py', ignore_deprecated=True, check_aliases=True) + + if filename is None: + continue + if filename.endswith(".ps1"): + continue + if os.path.isdir(filename): + continue + + text.append("%-*s %-*.*s" % (displace, plugin, linelimit, len(filename), filename)) + + except Exception as e: + raise AnsibleError("Failed reading docs at %s: %s" % (plugin, to_native(e))) + + return "\n".join(text) + @staticmethod def print_paths(finder): ''' Returns a string suitable for printing of the search path '''