asdf
asdf copied to clipboard
bug: `asdf current <name>` outputs more than just the current version
Describe the Bug
The asdf current <name> command does more than just "display current version set or being used for package" as the help message says. Also, this command in the documentation does not work due to that:
https://github.com/asdf-vm/asdf/blob/a91b6d0ee3bc87af0af3cd4b29dd74695e8026b8/docs/manage/versions.md?plain=1#L150
I could not track how far the behavior changed, if it changed at all, or if the documentation was just wrong since the beginning.
It would be handy to have a raw output of just the version so it could be used as the example. A use case I have is trying to check if the system version of direnv is currently being used or not (for this).
EDIT: I see asdf where will already output the install path of the current version installed if no specific version is given, so the documentation should be updated. I'll submit a PR for that.
Steps to Reproduce
asdf current direnv
Expected Behaviour
2.32.2
Actual Behaviour
direnv 2.32.2 /path/to/.tool-versions
Environment
OS:
Darwin me.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Dec 19 20:44:01 PST 2022; root:xnu-8020.240.18~2/RELEASE_X86_64 x86_64
SHELL:
zsh 5.9 (x86_64-apple-darwin21.3.0)
ASDF VERSION:
v0.11.1
ASDF ENVIRONMENT VARIABLES:
ASDF_DIR=/usr/local/opt/asdf/libexec
ASDF INSTALLED PLUGINS:
direnv https://github.com/asdf-community/asdf-direnv.git master e3622e6
nodejs https://github.com/asdf-vm/asdf-nodejs.git master c9e5df4
python https://github.com/danhper/asdf-python.git master 8505457
asdf plugins affected (if relevant)
No response
Yeah this doesn't seem right... I see the output of this command changed between versions 0.7.8 and 0.8.0. 0.8.0 is what introduced the current output. I agree we either need to revert to just the version number, OR add a flag so that only the version number is printed.
I agree. I can see why asdf current without any arguments prints an index by tool, but if you provide the name of a single tool, that format feels redundant—even more so because you can't specify multiple tools, it's one or all.
In my case, to use this in a script, I'm having to something like asdf current $tool | tr -s ' ' ' ' | cut -d' ' -f2 so that's pretty unwieldy.
Perhaps this is also part of a broader discussion about canonical parseable output and maybe even a --json switch to stream into jq, for example?
I come from pyenv and rbenv. These tools have a pretty good design in my opinion:
rbenv version: outputs verbosely:3.0.2 (set by /Users/myself/.rbenv/version)rbenv version-name: outputs the desired version:3.0.2rbenv version-origin: outputs where it has been set:/Users/myself/.rbenv/version- if
rbenv shell 2.7.8have been used it says:RBENV_VERSION environment variable
- if
rbenv version-file: outputs the/Users/myself/.rbenv/version- this always shows the file, even if a shell version has been set
I like this approach - I think asdf current and asdf current direnv should match this behaviour:
- for plugin-specific listing this would work:
asdf current-name direnvasdf current-origin direnvasdf current-file direnv
- for general listing I do not know what they would do
- maybe the plugin name would be mandatory for these, so the command would return with and error
Unless someone has good arguments for an alternative - like using options instead of differently named subcommands.
@mrmeszaros We could certainly add these other capabilities. For the short term, as @Stratus3D mentioned, this seems like a regression introduced in 0.8.0, so for closing this we should simply resolve that.
After that we can circle back and add some flag(s) to the command, like --verbose, to show origin, env vars etc. Commands that simply perform a cat of the version file seem a bit redundant when that is easily retrieved with say an --origin flag.
Have you had the opportunity to make progress on the subject?