Support pyenv local --force
This commit is contained in:
parent
057d7ad445
commit
a9c5e18235
@ -2,9 +2,11 @@
|
||||
#
|
||||
# Summary: Set or show the local application-specific Python version(s)
|
||||
#
|
||||
# Usage: pyenv local <version> <version2> <..>
|
||||
# Usage: pyenv local [-f|--force] [<version> [...]]
|
||||
# pyenv local --unset
|
||||
#
|
||||
# -f/--force Do not verify that the versions being set exist
|
||||
#
|
||||
# Sets the local application-specific Python version(s) by writing the
|
||||
# version name to a file named `.python-version'.
|
||||
#
|
||||
@ -36,12 +38,25 @@ if [ "$1" = "--complete" ]; then
|
||||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case "$1" in
|
||||
-f|--force)
|
||||
FORCE=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
versions=("$@")
|
||||
|
||||
if [ "$versions" = "--unset" ]; then
|
||||
rm -f .python-version
|
||||
elif [ -n "$versions" ]; then
|
||||
pyenv-version-file-write .python-version "${versions[@]}"
|
||||
pyenv-version-file-write ${FORCE:+-f }.python-version "${versions[@]}"
|
||||
else
|
||||
if version_file="$(pyenv-version-file "$PWD")"; then
|
||||
IFS=: versions=($(pyenv-version-file-read "$version_file"))
|
||||
|
@ -41,6 +41,18 @@ setup() {
|
||||
assert [ "$(cat .python-version)" = "1.2.3" ]
|
||||
}
|
||||
|
||||
@test "fails to set a nonexistent local version" {
|
||||
run pyenv-local 1.2.3
|
||||
assert_failure "pyenv: version \`1.2.3' not installed"
|
||||
assert [ ! -e .python-version ]
|
||||
}
|
||||
|
||||
@test "sets a nonexistent local version with --force" {
|
||||
run pyenv-local -f 1.2.3
|
||||
assert_success ""
|
||||
assert [ "$(cat .python-version)" = "1.2.3" ]
|
||||
}
|
||||
|
||||
@test "changes local version" {
|
||||
echo "1.0-pre" > .python-version
|
||||
mkdir -p "${PYENV_ROOT}/versions/1.2.3"
|
||||
|
Loading…
x
Reference in New Issue
Block a user