Skip to content
This repository was archived by the owner on Dec 23, 2018. It is now read-only.

Commit 12bbef5

Browse files
committed
phpenv-uninstall prompts before removal unless invoked with -f
1 parent a53855d commit 12bbef5

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

bin/phpenv-uninstall

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,32 @@ set -e
33

44
# Provide phpenv completions
55
if [ "$1" = "--complete" ]; then
6-
exec php-build --definitions
6+
exec phpenv versions --bare
77
fi
88

99
if [ -z "$PHPENV_ROOT" ]; then
1010
PHPENV_ROOT="${HOME}/.phpenv"
1111
fi
1212

13+
if [ "$1" = "-f" ]; then
14+
FORCE=1
15+
shift
16+
else
17+
FORCE=""
18+
fi
19+
1320
DEFINITION="$1"
1421
case "$DEFINITION" in
1522
"" | -* )
16-
{ echo "usage: phpenv uninstall VERSION"
17-
echo " phpenv uninstall /path/to/definition"
23+
{ echo "usage: phpenv uninstall [-f] VERSION"
24+
echo
25+
echo " -f Attempt to remove the specified version without prompting"
26+
echo " for confirmation. If the version does not exist, do not"
27+
echo " display an error message."
28+
echo
29+
echo "Available versions:"
30+
phpenv versions --bare | sed 's/^/ /'
1831
echo
19-
if [ -n `which phpenv` ]; then
20-
echo "Available versions:"
21-
phpenv versions | sed 's/^/ /'
22-
echo
23-
fi
2432
} >&2
2533
exit 1
2634
;;
@@ -29,9 +37,20 @@ esac
2937
VERSION_NAME="${DEFINITION##*/}"
3038
PREFIX="${PHPENV_ROOT}/versions/${VERSION_NAME}"
3139

32-
if [ ! -e "$PREFIX" ]; then
33-
echo "Given version ($VERSION_NAME) is not installed"
34-
exit 1
40+
if [ -z "$FORCE" ]; then
41+
if [ ! -d "$PREFIX" ]; then
42+
echo "phpenv: version \`$VERSION_NAME' not installed" >&2
43+
exit 1
44+
fi
45+
46+
read -p "phpenv: remove $PREFIX? "
47+
case "$REPLY" in
48+
y* | Y* ) ;;
49+
* ) exit 1 ;;
50+
esac
51+
fi
52+
53+
if [ -d "$PREFIX" ]; then
54+
rm -rf "$PREFIX"
55+
phpenv rehash
3556
fi
36-
rm -rf "$PREFIX"
37-
phpenv rehash

0 commit comments

Comments
 (0)