From 1b34933414551dde61572f43d23602505b090f42 Mon Sep 17 00:00:00 2001 From: Richie B2B Date: Fri, 19 Nov 2021 16:29:47 +0100 Subject: [PATCH] Fix ansible-doc -l ansible.builtin / ansible.legacy (#76235) --- .../76235-fix-ansible-doc-builtin-legacy.yml | 2 ++ lib/ansible/cli/doc.py | 2 +- test/units/cli/test_doc.py | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/76235-fix-ansible-doc-builtin-legacy.yml diff --git a/changelogs/fragments/76235-fix-ansible-doc-builtin-legacy.yml b/changelogs/fragments/76235-fix-ansible-doc-builtin-legacy.yml new file mode 100644 index 00000000000..f140684e77a --- /dev/null +++ b/changelogs/fragments/76235-fix-ansible-doc-builtin-legacy.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-doc - Fix ansible-doc -l ansible.builtin / ansible.legacy not returning anything diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index 27dc9418fea..c264aff4fcb 100755 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -595,7 +595,7 @@ class DocCLI(CLI, RoleMixin): if len(context.CLIARGS['args']) == 1: coll_filter = context.CLIARGS['args'][0] - if coll_filter in ('', None): + if coll_filter in ('ansible.builtin', 'ansible.legacy', '', None): paths = loader._get_paths_with_context() for path_context in paths: self.plugin_list.update(DocCLI.find_plugins(path_context.path, path_context.internal, plugin_type)) diff --git a/test/units/cli/test_doc.py b/test/units/cli/test_doc.py index 5cdf974b4b8..576bdb28fe8 100644 --- a/test/units/cli/test_doc.py +++ b/test/units/cli/test_doc.py @@ -5,6 +5,7 @@ __metaclass__ = type import pytest from ansible.cli.doc import DocCLI, RoleMixin +from ansible.plugins.loader import module_loader TTY_IFY_DATA = { @@ -111,3 +112,19 @@ def test_rolemixin__build_doc_no_filter_match(): fqcn, doc = obj._build_doc(role_name, path, collection_name, argspec, entrypoint_filter) assert fqcn == '.'.join([collection_name, role_name]) assert doc is None + + +def test_builtin_modules_list(): + args = ['ansible-doc', '-l', 'ansible.builtin', '-t', 'module'] + obj = DocCLI(args=args) + obj.parse() + result = obj._list_plugins('module', module_loader) + assert len(result) > 0 + + +def test_legacy_modules_list(): + args = ['ansible-doc', '-l', 'ansible.legacy', '-t', 'module'] + obj = DocCLI(args=args) + obj.parse() + result = obj._list_plugins('module', module_loader) + assert len(result) > 0