Support pyenv-version-file-write --force

This commit is contained in:
Ivan Pozdeev 2024-12-15 19:32:49 +03:00
parent 527d8fab3e
commit 057d7ad445
2 changed files with 23 additions and 2 deletions

View File

@ -1,9 +1,23 @@
#!/usr/bin/env bash
# Usage: pyenv version-file-write <file> <version>
# Usage: pyenv version-file-write [-f|--force] <file> <version>
set -e
[ -n "$PYENV_DEBUG" ] && set -x
while [[ $# -gt 0 ]]
do
case "$1" in
-f|--force)
FORCE=1
shift
;;
*)
break
;;
esac
done
PYENV_VERSION_FILE="$1"
shift || true
versions=("$@")
@ -14,7 +28,7 @@ if [ -z "$versions" ] || [ -z "$PYENV_VERSION_FILE" ]; then
fi
# Make sure the specified version is installed.
pyenv-prefix "${versions[@]}" >/dev/null
[[ -z $FORCE ]] && pyenv-prefix "${versions[@]}" >/dev/null
# Write the version out to disk.
# Create an empty file. Using "rm" might cause a permission error.

View File

@ -21,6 +21,13 @@ setup() {
assert [ ! -e ".python-version" ]
}
@test "setting nonexistent version succeeds with force" {
assert [ ! -e ".python-version" ]
run pyenv-version-file-write --force ".python-version" "2.7.6"
assert_success
assert [ -e ".python-version" ]
}
@test "writes value to arbitrary file" {
mkdir -p "${PYENV_ROOT}/versions/2.7.6"
assert [ ! -e "my-version" ]