aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsanmiguel <[email protected]>2017-02-18 13:40:01 +0100
committersanmiguel <[email protected]>2017-02-18 13:40:01 +0100
commit9a3205b326eda1b906c8078c11af914fec2be1fb (patch)
treeb8350d9bfd4b30d0f72b862c2268e2d6b7051e84
parentc684e654274d65577d7133d6d22e5e7be17a6ee8 (diff)
downloadkerl-9a3205b326eda1b906c8078c11af914fec2be1fb.tar.gz
kerl-9a3205b326eda1b906c8078c11af914fec2be1fb.tar.bz2
kerl-9a3205b326eda1b906c8078c11af914fec2be1fb.zip
Flesh out 'kerl path'
-rwxr-xr-xkerl41
1 files changed, 17 insertions, 24 deletions
diff --git a/kerl b/kerl
index d18d532..2ea08e4 100755
--- a/kerl
+++ b/kerl
@@ -1200,24 +1200,6 @@ list_print()
echo "There are no $1 available"
}
-list_print1()
-{
- # TODO Assert that there is exactly 1 match
- # TODO This function is a misnomer because it's becoming
- # totally specialised to finding an installation by name
- # We really only want to match if a single install has a path
- # such that $(basename $installpath) == $2
- # There are some possible extensions to this we could
- # consider, such as:
- # - match as above if there's exactly 1 match
- # - if 2+ matches: prefer one in a subdir from $PWD
- # - prefer $KERL_DEFAULT_INSTALL_DIR
- # - probably more!
- # FIXME 'grep -w' treats '-' as word boundary, so a search for
- # 'foo-1' will match both '/path/foo-1' and '/path/bar-foo-1'
- grep -w "$2" "$KERL_BASE_DIR/otp_$1" 2>&1
-}
-
list_add()
{
if [ -f "$KERL_BASE_DIR/otp_$1" ]; then
@@ -1579,7 +1561,6 @@ case "$1" in
# kerl path <install>
# Print path to installation with name <install>, else non-zero exit
if [ -z "$2" ]; then
- # TODO Print a warning if no active path
activepath=$(get_active_path)
if [ -z "$activepath" ]; then
echo "No active kerl-managed erlang installation"
@@ -1587,11 +1568,23 @@ case "$1" in
fi
echo "$activepath"
else
- # TODO Move this inside something like assert_valid_installation
- # that either prints exactly 1 match or exits non-zero
- # TODO Print exactly 1 otherwise error
- activepath=$(list_print1 installations "$2" | cut -d' ' -f2)
- echo $activepath
+ # There are some possible extensions to this we could
+ # consider, such as:
+ # - if 2+ matches: prefer one in a subdir from $PWD
+ # - prefer $KERL_DEFAULT_INSTALL_DIR
+ match=
+ for ins in $(list_print installations | cut -d' ' -f2); do
+ if [ "$(basename $ins)" = "$2" ]; then
+ if [ -z "$match" ]; then
+ match="$ins"
+ else
+ echo "Error: too many matching installations" >&2
+ exit 2
+ fi
+ fi
+ done
+ [ -n "$match" ] && echo "$match" && exit 0
+ echo "Error: no matching installation found" >&2 && exit 1
fi
;;
delete)