Skip to content

Commit 25e214b

Browse files
committed
feat: Uninstall a package by passing it's directory name. Closes #29
1 parent da65586 commit 25e214b

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

pkg/lib/commands/do-uninstall.sh

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
# shellcheck shell=bash
22

3+
do-actual-uninstall() {
4+
local package="$1"
5+
6+
log.info "Uninstalling '$package'"
7+
do-plumbing-unlink-man "$package"
8+
do-plumbing-unlink-bins "$package"
9+
do-plumbing-unlink-completions "$package"
10+
11+
rm -rf "${BPM_PACKAGES_PATH:?}/$package"
12+
}
313
do-uninstall() {
414
if (( $# == 0 )); then
515
die "You must supply at least one package"
616
fi
717

818
for repoSpec; do
9-
local site= user= repository= ref=
10-
util.parse_package_full "$repoSpec"
11-
IFS=':' read -r site user repository ref <<< "$REPLY"
19+
if [ -d "$repoSpec" ]; then
20+
local fullPath=
21+
fullPath="$(util.readlink "$repoSpec")"
22+
fullPath="${fullPath%/}"
1223

13-
local package="$user/$repository"
24+
local user="${fullPath%/*}"; user="${user##*/}"
25+
local repository="${fullPath##*/}"
26+
if [ "$fullPath" == "$BPM_PACKAGES_PATH/$user/$repository" ]; then
27+
do-actual-uninstall "$user/$repository"
28+
fi
29+
else
30+
local site= user= repository= ref=
31+
util.parse_package_full "$repoSpec"
32+
IFS=':' read -r site user repository ref <<< "$REPLY"
1433

15-
if [ ! -e "$BPM_PACKAGES_PATH/$package" ]; then
16-
die "Package '$package' is not installed"
17-
fi
18-
19-
log.info "Uninstalling '$repoSpec'"
20-
do-plumbing-unlink-man "$package"
21-
do-plumbing-unlink-bins "$package"
22-
do-plumbing-unlink-completions "$package"
34+
if [ ! -e "$BPM_PACKAGES_PATH/$user/$repository" ]; then
35+
die "Package '$user/$repository' is not installed"
36+
fi
2337

24-
rm -rf "${BPM_PACKAGES_PATH:?}/$package"
38+
do-actual-uninstall "$user/$repository"
39+
fi
2540
done
2641
}

0 commit comments

Comments
 (0)