mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
add path info to role list (#49346)
* add path info to role list - use same display format for both listing all and specific roles Co-Authored-By: bcoca <bcoca@users.noreply.github.com>
This commit is contained in:
parent
0c1f62065c
commit
42a13d15f1
2 changed files with 21 additions and 18 deletions
2
changelogs/fragments/nicer_role_list.yml
Normal file
2
changelogs/fragments/nicer_role_list.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- now galaxy shows each path where it finds roles when listing them
|
|
@ -460,45 +460,46 @@ class GalaxyCLI(CLI):
|
||||||
if len(self.args) > 1:
|
if len(self.args) > 1:
|
||||||
raise AnsibleOptionsError("- please specify only one role to list, or specify no roles to see a full list")
|
raise AnsibleOptionsError("- please specify only one role to list, or specify no roles to see a full list")
|
||||||
|
|
||||||
|
def _display_role(gr):
|
||||||
|
install_info = gr.install_info
|
||||||
|
version = None
|
||||||
|
if install_info:
|
||||||
|
version = install_info.get("version", None)
|
||||||
|
if not version:
|
||||||
|
version = "(unknown version)"
|
||||||
|
display.display("- %s, %s" % (gr.name, version))
|
||||||
|
|
||||||
if len(self.args) == 1:
|
if len(self.args) == 1:
|
||||||
# show only the request role, if it exists
|
# show the requested role, if it exists
|
||||||
name = self.args.pop()
|
name = self.args.pop()
|
||||||
gr = GalaxyRole(self.galaxy, name)
|
gr = GalaxyRole(self.galaxy, name)
|
||||||
if gr.metadata:
|
if gr.metadata:
|
||||||
install_info = gr.install_info
|
display.display('# %s' % os.path.dirname(gr.path))
|
||||||
version = None
|
_display_role(gr)
|
||||||
if install_info:
|
|
||||||
version = install_info.get("version", None)
|
|
||||||
if not version:
|
|
||||||
version = "(unknown version)"
|
|
||||||
# show some more info about single roles here
|
|
||||||
display.display("- %s, %s" % (name, version))
|
|
||||||
else:
|
else:
|
||||||
display.display("- the role %s was not found" % name)
|
display.display("- the role %s was not found" % name)
|
||||||
else:
|
else:
|
||||||
# show all valid roles in the roles_path directory
|
# show all valid roles in the roles_path directory
|
||||||
roles_path = self.options.roles_path
|
roles_path = self.options.roles_path
|
||||||
path_found = False
|
path_found = False
|
||||||
|
warnings = []
|
||||||
for path in roles_path:
|
for path in roles_path:
|
||||||
role_path = os.path.expanduser(path)
|
role_path = os.path.expanduser(path)
|
||||||
if not os.path.exists(role_path):
|
if not os.path.exists(role_path):
|
||||||
display.warning("- the configured path %s does not exist." % role_path)
|
warnings.append("- the configured path %s does not exist." % role_path)
|
||||||
continue
|
continue
|
||||||
elif not os.path.isdir(role_path):
|
elif not os.path.isdir(role_path):
|
||||||
display.warning("- the configured path %s, exists, but it is not a directory." % role_path)
|
warnings.append("- the configured path %s, exists, but it is not a directory." % role_path)
|
||||||
continue
|
continue
|
||||||
|
display.display('# %s' % role_path)
|
||||||
path_files = os.listdir(role_path)
|
path_files = os.listdir(role_path)
|
||||||
path_found = True
|
path_found = True
|
||||||
for path_file in path_files:
|
for path_file in path_files:
|
||||||
gr = GalaxyRole(self.galaxy, path_file, path=path)
|
gr = GalaxyRole(self.galaxy, path_file, path=path)
|
||||||
if gr.metadata:
|
if gr.metadata:
|
||||||
install_info = gr.install_info
|
_display_role(gr)
|
||||||
version = None
|
for w in warnings:
|
||||||
if install_info:
|
display.warning(w)
|
||||||
version = install_info.get("version", None)
|
|
||||||
if not version:
|
|
||||||
version = "(unknown version)"
|
|
||||||
display.display("- %s, %s" % (path_file, version))
|
|
||||||
if not path_found:
|
if not path_found:
|
||||||
raise AnsibleOptionsError("- None of the provided paths was usable. Please specify a valid path with --roles-path")
|
raise AnsibleOptionsError("- None of the provided paths was usable. Please specify a valid path with --roles-path")
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue