1
0
Fork 0
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:
Brian Coca 2018-12-10 11:41:22 -05:00 committed by GitHub
parent 0c1f62065c
commit 42a13d15f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 18 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- now galaxy shows each path where it finds roles when listing them

View file

@ -460,45 +460,46 @@ class GalaxyCLI(CLI):
if len(self.args) > 1:
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:
# show only the request role, if it exists
# show the requested role, if it exists
name = self.args.pop()
gr = GalaxyRole(self.galaxy, name)
if gr.metadata:
install_info = gr.install_info
version = None
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))
display.display('# %s' % os.path.dirname(gr.path))
_display_role(gr)
else:
display.display("- the role %s was not found" % name)
else:
# show all valid roles in the roles_path directory
roles_path = self.options.roles_path
path_found = False
warnings = []
for path in roles_path:
role_path = os.path.expanduser(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
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
display.display('# %s' % role_path)
path_files = os.listdir(role_path)
path_found = True
for path_file in path_files:
gr = GalaxyRole(self.galaxy, path_file, path=path)
if gr.metadata:
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" % (path_file, version))
_display_role(gr)
for w in warnings:
display.warning(w)
if not path_found:
raise AnsibleOptionsError("- None of the provided paths was usable. Please specify a valid path with --roles-path")
return 0