diff options
author | Felix Fontein <felix@fontein.de> | 2022-07-05 17:30:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-05 08:30:01 -0700 |
commit | 036fc02c2793d54c04faee77478093ee86f19f3b (patch) | |
tree | 3245276bd515b7a72388880069ab6ab304b91288 | |
parent | 99217ca2b68909455b783811836d66589bd991d8 (diff) | |
download | ansible-036fc02c2793d54c04faee77478093ee86f19f3b.tar.gz |
[stable-2.13] ansible-doc: list modules in collections recursively (#78137)
* List modules in collections recursively.
* Skip symlinks when listing plugins and modules.
-rw-r--r-- | changelogs/fragments/78137-ansible-doc-list-modules-recursively.yml | 3 | ||||
-rwxr-xr-x | lib/ansible/cli/doc.py | 15 |
2 files changed, 13 insertions, 5 deletions
diff --git a/changelogs/fragments/78137-ansible-doc-list-modules-recursively.yml b/changelogs/fragments/78137-ansible-doc-list-modules-recursively.yml new file mode 100644 index 0000000000..66567bcc44 --- /dev/null +++ b/changelogs/fragments/78137-ansible-doc-list-modules-recursively.yml @@ -0,0 +1,3 @@ +bugfixes: + - "ansible-doc - when listing modules in collections, proceed recursively. This fixes module listing for community.general 5.x.y and community.network 4.x.y (https://github.com/ansible/ansible/pull/78137)." + - "ansible-doc - no longer list module and plugin aliases that are created with symlinks (https://github.com/ansible/ansible/pull/78137)." diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index 98ff8705a6..bbf1966a4f 100755 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -937,7 +937,7 @@ class DocCLI(CLI, RoleMixin): return text @staticmethod - def find_plugins(path, internal, ptype, collection=None): + def find_plugins(path, internal, ptype, collection=None, depth=0): # if internal, collection could be set to `ansible.builtin` display.vvvv("Searching %s for plugins" % path) @@ -960,6 +960,8 @@ class DocCLI(CLI, RoleMixin): if plugin.startswith('.'): continue elif os.path.isdir(full_path): + if ptype == 'module' and not plugin.startswith('__') and collection is not None and not internal: + plugin_list.update(DocCLI.find_plugins(full_path, False, ptype, collection=collection, depth=depth + 1)) continue elif any(plugin.endswith(x) for x in C.REJECT_EXTS): continue @@ -967,9 +969,8 @@ class DocCLI(CLI, RoleMixin): continue elif plugin in C.IGNORE_FILES: continue - elif plugin .startswith('_'): - if os.path.islink(full_path): # avoids aliases - continue + elif os.path.islink(full_path): # avoids aliases + continue plugin = os.path.splitext(plugin)[0] # removes the extension plugin = plugin.lstrip('_') # remove underscore from deprecated plugins @@ -977,7 +978,11 @@ class DocCLI(CLI, RoleMixin): if plugin not in REJECTLIST.get(bkey, ()): if collection: - plugin = '%s.%s' % (collection, plugin) + composite = [collection] + if depth: + composite.extend(path.split(os.path.sep)[depth * -1:]) + composite.append(plugin) + plugin = '.'.join(composite) plugin_list.add(plugin) display.vvvv("Added %s" % plugin) |