Skip to content

Commit

Permalink
fix: use return inseatof exit
Browse files Browse the repository at this point in the history
Previously, exit terminal accidenttilly when ni-assertPackageBySocket is failed
  • Loading branch information
azu authored Aug 20, 2023
1 parent bfa7cd8 commit bf02214
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ni.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function ni-assertPackageBySocket() {
# If input string contains '@', extract package version after the last '@'
echo "$(echo "$1" | rev | cut -d "@" -f 1 | rev)"
}

local pkg
local version
pkg=$(getPackageName "$1")
Expand All @@ -113,7 +113,7 @@ function ni-assertPackageBySocket() {
# if error reponse, then exit
if [ $? -ne 0 ]; then
echo "Error: $pkg is not found"
exit 1
return 1
fi
version=$(echo "${viewVersion}" | jq -r .)
fi
Expand All @@ -137,7 +137,7 @@ function ni-assertPackageBySocket() {
echo "Are you sure to install this package?[y/N]"
read yn
if [ "$yn" != "y" ]; then
exit 1
return 1
fi
elif [ $(echo "$score <= 0.5" | bc -l) -eq 1 ]; then
echo -e "⚠️ \033[33m$pkg@$version's score: $score\033[0m"
Expand All @@ -146,7 +146,7 @@ function ni-assertPackageBySocket() {
echo "Are you sure to install this package?[y/N]"
read yn
if [ "$yn" != "y" ]; then
exit 1
return 1
fi
else
echo -e "📦 \033[32m$pkg@$version's score: $score\033[0m"
Expand Down Expand Up @@ -236,6 +236,10 @@ function ni() {
function ni-add() {
# check package score
ni-assertPackageBySocket "$1"
if [[ $? -eq 1 ]]; then
return 1
fi

local manager
manager=$(getPackageManager)
# normailze flag by package manager
Expand Down

0 comments on commit bf02214

Please sign in to comment.