Add --bare option to pyenv version (#2783)

This commit is contained in:
Jesse Wattenbarger 2025-05-17 11:23:25 -04:00 committed by GitHub
parent 90fa430eca
commit 018ca73444
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 4 deletions

View File

@ -272,8 +272,15 @@ version of Python, or install a package that provides binaries.
Displays the currently active Python version, along with information on Displays the currently active Python version, along with information on
how it was set. how it was set.
Usage: pyenv version [--bare]
--bare show just the version name. An alias to `pyenv version-name'
$ pyenv version $ pyenv version
2.7.6 (set by /home/yyuu/.pyenv/version) 2.7.6 (set by /home/yyuu/.pyenv/version)
$ pyenv version --bare
2.7.6
## `pyenv versions` ## `pyenv versions`

View File

@ -1,9 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Summary: Show the current Python version(s) and its origin # Summary: Show the current Python version(s) and its origin
# Usage: pyenv version [--bare]
# #
# Shows the currently selected Python version(s) and how it was # --bare show just the version name. An alias to `pyenv version-name'
# selected. To obtain only the version string, use `pyenv
# version-name'.
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
@ -13,8 +12,25 @@ OLDIFS="$IFS"
IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) || exitcode=$? IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) || exitcode=$?
IFS="$OLDIFS" IFS="$OLDIFS"
unset bare
for arg; do
case "$arg" in
--complete )
echo --bare
exit ;;
--bare ) bare=1 ;;
* )
pyenv-help --usage version >&2
exit 1
;;
esac
done
for PYENV_VERSION_NAME in "${PYENV_VERSION_NAMES[@]}"; do for PYENV_VERSION_NAME in "${PYENV_VERSION_NAMES[@]}"; do
echo "$PYENV_VERSION_NAME (set by $(pyenv-version-origin))" if [[ -n $bare ]]; then
echo "$PYENV_VERSION_NAME"
else
echo "$PYENV_VERSION_NAME (set by $(pyenv-version-origin))"
fi
done done
exit $exitcode exit $exitcode

View File

@ -70,3 +70,12 @@ pyenv-version-without-stderr() {
3.3.3 (set by PYENV_VERSION environment variable) 3.3.3 (set by PYENV_VERSION environment variable)
OUT OUT
} }
@test "--bare prints just the name" {
create_version "3.3.3"
PYENV_VERSION=3.3.3 run pyenv-version --bare
assert_success
assert_output <<OUT
3.3.3
OUT
}