New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: sort listing by version number in natural order #1100
fix: sort listing by version number in natural order #1100
Conversation
Hi @kianmeng are you able to share resources on how portable Tests would also need to be updated, ideally with versions that exhibit this behaviour should a regression occur. |
I will assume the supported OSes are GNU/Linux and macOS and supported Shells are Bash, Zsh, and Fish? Is there any minimum version requirement for these Shells?
Noted. |
This is mostly it. OSs: GNU/Linux, macOS. Shells: Bash, ZSH, Fish, Elvish.
We don't have official version targets (something we wish to capture), but as low as possible. |
@@ -95,8 +95,7 @@ list_installed_versions() { | |||
plugin_installs_path="$(asdf_data_dir)/installs/${plugin_name}" | |||
|
|||
if [ -d "$plugin_installs_path" ]; then | |||
for install in "${plugin_installs_path}"/*/; do | |||
[[ -e "$install" ]] || break | |||
for install in $(ls -1v ${plugin_installs_path}); do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to achieve this without ls
? I've been considering banning ls
from the codebase because it's caused a couple bugs in the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None I can think of or found. Perhaps we can't or shouldn't implement this feature since using ls
is not universal applicable for all platforms.
Your thoughts? @jthegedus @Stratus3D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be possible to do this with sort
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess part of the problem here is that when we list all versions of a plugin, we call out to the plugin's list-all
callback, which is responsible for returning versions in the correct order. Here we are dealing with a subset of those same versions, but we don't have a way of calling out to the plugin to sort them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we could add another plugin callback that would receive a list of versions and would be expected to sort them, but I'm not sure it would be worth the hassle (we'd have to implement it in every plugin, or default to sorting versions as semantic versions.
Thanks for your PR @kianmeng . I'm sorry I did not give you feedback sooner. We decided to move forward with banning If you can achieve this with |
@Stratus3D Noted, and thanks for the explanation. |
Summary
This PR fixes the issue where the installed versions from
asdf list
orasdf list <plugin
command are not sorted in natural order.Other Information
Before:
After: