mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-07 20:31:01 -05:00
Extract abort
helper function
fail helper prints message to stderr and exits 1 (prefixes 'rbenv: ' if given a string arg)
This commit is contained in:
parent
63671a1479
commit
3ddedc021a
1 changed files with 14 additions and 18 deletions
|
@ -12,21 +12,24 @@ if [ -n "$RBENV_DEBUG" ]; then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
abort() {
|
||||||
|
{ if [ "$#" -eq 0 ]; then cat -
|
||||||
|
else echo "rbenv: $*"
|
||||||
|
fi
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
|
if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
|
||||||
abs_dirname() {
|
abs_dirname() {
|
||||||
local path="$(realpath "$1")"
|
local path="$(realpath "$1")"
|
||||||
echo "${path%/*}"
|
echo "${path%/*}"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if [ -n "$RBENV_NATIVE_EXT" ]; then
|
[ -z "$RBENV_NATIVE_EXT" ] || abort "failed to load \`realpath' builtin"
|
||||||
echo "rbenv: failed to load \`realpath' builtin" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
READLINK=$(type -p greadlink readlink | head -1)
|
READLINK=$(type -p greadlink readlink | head -1)
|
||||||
if [ -z "$READLINK" ]; then
|
[ -n "$READLINK" ] || abort "cannot find readlink - are you missing GNU coreutils?"
|
||||||
echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
resolve_link() {
|
resolve_link() {
|
||||||
$READLINK "$1"
|
$READLINK "$1"
|
||||||
|
@ -57,10 +60,7 @@ export RBENV_ROOT
|
||||||
if [ -z "${RBENV_DIR}" ]; then
|
if [ -z "${RBENV_DIR}" ]; then
|
||||||
RBENV_DIR="$(pwd)"
|
RBENV_DIR="$(pwd)"
|
||||||
else
|
else
|
||||||
cd "$RBENV_DIR" 2>/dev/null || {
|
cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'"
|
||||||
echo "rbenv: cannot change working directory to \`$RBENV_DIR'"
|
|
||||||
exit 1
|
|
||||||
} >&2
|
|
||||||
RBENV_DIR="$(pwd)"
|
RBENV_DIR="$(pwd)"
|
||||||
cd "$OLDPWD"
|
cd "$OLDPWD"
|
||||||
fi
|
fi
|
||||||
|
@ -94,8 +94,7 @@ case "$command" in
|
||||||
"" )
|
"" )
|
||||||
{ rbenv---version
|
{ rbenv---version
|
||||||
rbenv-help
|
rbenv-help
|
||||||
} >&2
|
} | abort
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
-v | --version )
|
-v | --version )
|
||||||
exec rbenv---version
|
exec rbenv---version
|
||||||
|
@ -105,10 +104,7 @@ case "$command" in
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
command_path="$(command -v "rbenv-$command" || true)"
|
command_path="$(command -v "rbenv-$command" || true)"
|
||||||
if [ -z "$command_path" ]; then
|
[ -n "$command_path" ] || abort "no such command \`$command'"
|
||||||
echo "rbenv: no such command \`$command'" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift 1
|
shift 1
|
||||||
if [ "$1" = --help ]; then
|
if [ "$1" = --help ]; then
|
||||||
|
|
Loading…
Reference in a new issue