Support pyenv-version-file-write --force
This commit is contained in:
parent
527d8fab3e
commit
057d7ad445
@ -1,9 +1,23 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Usage: pyenv version-file-write <file> <version>
|
# Usage: pyenv version-file-write [-f|--force] <file> <version>
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
-f|--force)
|
||||||
|
FORCE=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
PYENV_VERSION_FILE="$1"
|
PYENV_VERSION_FILE="$1"
|
||||||
shift || true
|
shift || true
|
||||||
versions=("$@")
|
versions=("$@")
|
||||||
@ -14,7 +28,7 @@ if [ -z "$versions" ] || [ -z "$PYENV_VERSION_FILE" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Make sure the specified version is installed.
|
# 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.
|
# Write the version out to disk.
|
||||||
# Create an empty file. Using "rm" might cause a permission error.
|
# Create an empty file. Using "rm" might cause a permission error.
|
||||||
|
@ -21,6 +21,13 @@ setup() {
|
|||||||
assert [ ! -e ".python-version" ]
|
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" {
|
@test "writes value to arbitrary file" {
|
||||||
mkdir -p "${PYENV_ROOT}/versions/2.7.6"
|
mkdir -p "${PYENV_ROOT}/versions/2.7.6"
|
||||||
assert [ ! -e "my-version" ]
|
assert [ ! -e "my-version" ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user