improve arguments handling

This commit is contained in:
Yamashita Yuu
2013-06-18 23:26:09 +09:00
parent 1ad6788e84
commit 551956f017

View File

@@ -121,19 +121,29 @@ for option in "${OPTIONS[@]}"; do
esac esac
done done
# If there is only one argument left, use current version as source version of virtualenv if [[ "${#ARGUMENTS[@]}" == 0 ]]; then
if [ "${#ARGUMENTS[@]}" -gt 1 ]; then echo "pyenv: no virtualenv name given." 1>&2
VERSION_NAME="${ARGUMENTS[0]}" exit 1
VIRTUALENV_NAME="${ARGUMENTS[1]##*/}" elif [[ "${#ARGUMENTS[@]}" == 1 ]]; then
else # If only one argument given, use current version as source version
VERSION_NAME="$(pyenv-version-name)" VERSION_NAME="$(pyenv-version-name)"
VIRTUALENV_NAME="${ARGUMENTS[0]}" VIRTUALENV_NAME="${ARGUMENTS[0]}"
else
# Otherwise, use former as source version, and latter as virtualenv version
VERSION_NAME="${ARGUMENTS[0]}"
VIRTUALENV_NAME="${ARGUMENTS[1]##*/}"
fi
if [ -z "${VERSION_NAME}" ] || [ -z "${VIRTUALENV_NAME}" ]; then
usage 1
fi fi
# Set VERSION_NAME as default version in this script # Set VERSION_NAME as default version in this script
[ -n "$VERSION_NAME" ] || usage 1
export PYENV_VERSION="${VERSION_NAME}" export PYENV_VERSION="${VERSION_NAME}"
# Source version must exists before creating virtualenv
pyenv-prefix 1>/dev/null 2>&1 || usage 1
if [ -z "$TMPDIR" ]; then if [ -z "$TMPDIR" ]; then
TMP="/tmp" TMP="/tmp"
else else
@@ -220,7 +230,7 @@ cd "${PYENV_VIRTUALENV_CACHE_PATH}"
pyenv-exec virtualenv "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?" pyenv-exec virtualenv "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?"
# Create symlink of `python' bound for actual executable # Create symlink of `python' bound for actual executable
# TODO: remove this if virtualenv treats `python` executable # TODO: remove this if virtualenv doesn't really need this
if [ ! -e "${VIRTUALENV_PATH}/bin/python" ]; then if [ ! -e "${VIRTUALENV_PATH}/bin/python" ]; then
PYTHON_BIN="$(pyenv-which python)" PYTHON_BIN="$(pyenv-which python)"
if [ -L "${PYTHON_BIN}" ] && [ -e "${VIRTUALENV_PATH}/bin/$(basename "$(resolve_link "${PYTHON_BIN}")")" ]; then if [ -L "${PYTHON_BIN}" ] && [ -e "${VIRTUALENV_PATH}/bin/$(basename "$(resolve_link "${PYTHON_BIN}")")" ]; then