Skip to content

Commit 854b25f

Browse files
committed
refactor: Small miscellaneous changes to keep code DRY
1 parent f1a19a0 commit 854b25f

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

pkg/lib/commands/do-list.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ do-list() {
3434
done
3535
else
3636
for package_path in "$BPM_PACKAGES_PATH"/*/*/*; do
37-
local site="${package_path%/*}"; site="${site%/*}"; site="${site##*/}"
38-
local user="${package_path%/*}"; user="${user##*/}"
39-
local repository="${package_path##*/}"
40-
local package="$user/$repository"
37+
util.extract_data_from_package_dir "$package_path"
38+
local site="$REPLY1"
39+
local package="$REPLY2/$REPLY3"
4140

4241
# Users that have installed packages before the switch to namespacing by
4342
# site domain name will print incorrectly. So, we check to make sure the site

pkg/lib/commands/do-plumbing-clone.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ do-plumbing-clone() {
66
local ref="$3"
77

88
ensure.non_zero 'uri' "$uri"
9-
# TODO: ensure.non_zero 'id'
9+
ensure.non_zero 'id' "$id"
1010

1111
if [ -e "$BPM_PACKAGES_PATH/$id" ]; then
1212
die "Package '$id' is already present"

pkg/lib/commands/do-remove.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ do-remove() {
99
# If is local directory
1010
# TODO: do this for upgrade as well
1111
if [ -d "$repoSpec" ]; then
12-
local fullPath=
13-
fullPath="$(util.readlink "$repoSpec")"
14-
fullPath="${fullPath%/}"
12+
local dir=
13+
dir="$(util.readlink "$repoSpec")"
14+
dir="${dir%/}"
1515

16-
# TODO: make this a funcion, share it with do-list
17-
local site="${fullPath%/*}"; site="${site%/*}"; site="${site##*/}"
18-
local user="${fullPath%/*}"; user="${user##*/}"
19-
local repository="${fullPath##*/}"
20-
local package="$user/$repository"
16+
util.extract_data_from_package_dir "$dir"
17+
local site="$REPLY1"
18+
local package="$REPLY2/$REPLY3"
2119

22-
if [ "$fullPath" = "$BPM_PACKAGES_PATH/$site/$package" ]; then
20+
if [ "$dir" = "$BPM_PACKAGES_PATH/$site/$package" ]; then
2321
do_actual_removal "$site/$package"
2422
fi
2523
else
2624
util.construct_clone_url "$repoSpec"
27-
local uri="$REPLY1"
2825
local site="$REPLY2"
2926
local package="$REPLY3"
3027
local ref="$REPLY4"

pkg/lib/util/abstract-completions.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ abstract.completions_do_action_zsh() {
104104
local file="$2"
105105

106106
if grep -qs "^#compdef" "$file"; then
107-
# TODO: run mkdir outside of loop
108107
case "$action" in
109108
link)
110109
mkdir -p "$BPM_INSTALL_COMPLETIONS/zsh/compsys"

pkg/lib/util/util.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ util.construct_clone_url() {
104104
fi
105105
}
106106

107+
# @description Given a path to a package directory, this extracts
108+
# data like the site it was cloned from, the owner of
109+
# the repository, and the name of the repository
110+
util.extract_data_from_package_dir() {
111+
REPLY1=
112+
REPLY2=
113+
REPLY3=
114+
115+
local dir="$1"
116+
ensure.non_zero 'dir' "$dir"
117+
118+
local site="${dir%/*}"; site="${site%/*}"; site="${site##*/}"
119+
local user="${dir%/*}"; user="${user##*/}"
120+
local repository="${dir##*/}"
121+
122+
REPLY1="$site"
123+
REPLY2="$user"
124+
REPLY3="$repository"
125+
}
126+
107127
util.readlink() {
108128
if command -v realpath &>/dev/null; then
109129
realpath "$1"

0 commit comments

Comments
 (0)