Add --bare option to pyenv version
(#2783)
This commit is contained in:
parent
90fa430eca
commit
018ca73444
@ -272,8 +272,15 @@ version of Python, or install a package that provides binaries.
|
||||
Displays the currently active Python version, along with information on
|
||||
how it was set.
|
||||
|
||||
Usage: pyenv version [--bare]
|
||||
|
||||
--bare show just the version name. An alias to `pyenv version-name'
|
||||
|
||||
|
||||
$ pyenv version
|
||||
2.7.6 (set by /home/yyuu/.pyenv/version)
|
||||
$ pyenv version --bare
|
||||
2.7.6
|
||||
|
||||
|
||||
## `pyenv versions`
|
||||
|
@ -1,9 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# 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
|
||||
# selected. To obtain only the version string, use `pyenv
|
||||
# version-name'.
|
||||
# --bare show just the version name. An alias to `pyenv version-name'
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
@ -13,8 +12,25 @@ OLDIFS="$IFS"
|
||||
IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name)) || exitcode=$?
|
||||
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
|
||||
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
|
||||
|
||||
exit $exitcode
|
||||
|
@ -70,3 +70,12 @@ pyenv-version-without-stderr() {
|
||||
3.3.3 (set by PYENV_VERSION environment variable)
|
||||
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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user