Skip to content

Commit 56f51ad

Browse files
committed
refactor: Knock off some TODO's within codebase
This also introduces some code relating to global and project-specific installation. It's not in a separate commit
1 parent bdacf49 commit 56f51ad

File tree

9 files changed

+80
-61
lines changed

9 files changed

+80
-61
lines changed

pkg/lib/cmd/bpm.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ main() {
2727
EOF
2828
exit
2929
;;
30+
--global)
31+
declare -rg BPM_MODE_GLOBAL=
32+
;;
3033
*)
3134
break
3235
;;

pkg/lib/commands/do-link.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,27 @@ do-link() {
1919
die "You must supply at least one directory"
2020
fi
2121

22-
for directory in "${dirs[@]}"; do
23-
if [ ! -d "$directory" ]; then
24-
die "Directory '$directory' not found"
22+
for dir in "${dirs[@]}"; do
23+
if [ ! -d "$dir" ]; then
24+
die "Directory '$dir' not found"
2525
fi
2626

27-
directory="$(util.readlink "$directory")"
27+
dir="$(util.readlink "$dir")"
28+
dir="${dir%/}"
2829

29-
local namespace="bpm-local"
30-
local repository="${directory##*/}"
31-
local package="$namespace/$repository"
30+
31+
local user="local"
32+
local repository="${dir##*/}"
33+
local package="$user/$repository"
3234

3335
if [ -e "$BPM_PACKAGES_PATH/$package" ]; then
3436
die "Package '$package' is already present"
3537
fi
3638

37-
# TODO: local git clone
38-
mkdir -p "$BPM_PACKAGES_PATH/$namespace"
39-
ln -s "$directory" "$BPM_PACKAGES_PATH/$package"
39+
mkdir -p "$BPM_PACKAGES_PATH/$user"
40+
ln -s "$dir" "$BPM_PACKAGES_PATH/$package"
4041

41-
log.info "Linking '$directory'"
42+
log.info "Linking '$dir'"
4243
if [ "$install_deps" = 'yes' ]; then
4344
do-plumbing-add-deps "$package"
4445
fi

pkg/lib/commands/do-list.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ do-list() {
4141
# Users that have installed packages before the switch to namespacing by
4242
# site domain name will print incorrectly. So, we check to make sure the site
4343
# url is actually is a domain name and not, for example, a GitHub username
44-
if [[ "$site" != *.* ]]; then
44+
if [[ "$site" != *.* ]] && [ "$site" != 'local' ]; then
4545
has_invalid_packages='yes'
4646
continue
4747
fi

pkg/lib/commands/do-upgrade.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,20 @@ do-upgrade() {
5959
do_actual_upgrade() {
6060
local id="$1"
6161

62-
log.info "Upgrading '$id'"
63-
do-plumbing-remove-deps "$id"
64-
do-plumbing-unlink-bins "$id"
65-
do-plumbing-unlink-completions "$id"
66-
do-plumbing-unlink-man "$id"
67-
git -C "$BPM_PACKAGES_PATH/$id" pull
68-
do-plumbing-add-deps "$id"
69-
do-plumbing-link-bins "$id"
70-
do-plumbing-link-completions "$id"
71-
do-plumbing-link-man "$id"
62+
# Only upgrade if the package is a Git repository. If it is not, then
63+
# it's a package installed with 'link'
64+
if [ -d "$BPM_PACKAGES_PATH/$id/.git" ]; then
65+
log.info "Upgrading '$id'"
66+
do-plumbing-remove-deps "$id"
67+
do-plumbing-unlink-bins "$id"
68+
do-plumbing-unlink-completions "$id"
69+
do-plumbing-unlink-man "$id"
70+
git -C "$BPM_PACKAGES_PATH/$id" pull
71+
do-plumbing-add-deps "$id"
72+
do-plumbing-link-bins "$id"
73+
do-plumbing-link-completions "$id"
74+
do-plumbing-link-man "$id"
75+
else
76+
log.warn "Package '$id' has been added with 'bpm link'. It cannot be upgraded"
77+
fi
7278
}

pkg/lib/util/util.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ util.extract_shell_variable() {
252252
util.show_help() {
253253
cat <<"EOF"
254254
Usage:
255-
bpm [--help|--version] <command> [args...]
255+
bpm [--help|--version|--global] <command> [args...]
256256
257257
Subcommands:
258258
init <shell>
@@ -266,7 +266,7 @@ Subcommands:
266266
267267
link [--no-deps] <directory...>
268268
Installs a local directory as a bpm package. These show up with
269-
a namespace of 'bpm-local'
269+
a namespace of 'local'
270270
271271
list [--outdated]
272272
List installed packages

tests/do-link.bats

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ load 'util/init.sh'
3131
run do-link 'theta'
3232

3333
assert_failure
34-
assert_line -n 0 -p "Package 'bpm-local/theta' is already present"
34+
assert_line -n 0 -p "Package 'local/theta' is already present"
3535
}
3636

3737
@test "fails if package already present (as erroneous file)" {
@@ -40,17 +40,17 @@ load 'util/init.sh'
4040
test_util.mock_command do-plumbing-link-completions
4141
test_util.mock_command do-plumbing-link-man
4242

43-
mkdir -p touch "$BPM_PACKAGES_PATH/bpm-local"
44-
touch "$BPM_PACKAGES_PATH/bpm-local/theta"
43+
mkdir -p touch "$BPM_PACKAGES_PATH/local"
44+
touch "$BPM_PACKAGES_PATH/local/theta"
4545
mkdir 'theta'
4646

4747
run do-link 'theta'
4848

4949
assert_failure
50-
assert_line -n 0 -p "Package 'bpm-local/theta' is already present"
50+
assert_line -n 0 -p "Package 'local/theta' is already present"
5151
}
5252

53-
@test "links the package to packages under the correct namespace (bpm-local)" {
53+
@test "links the package to packages under the correct namespace (local)" {
5454
test_util.mock_command do-plumbing-add-deps
5555
test_util.mock_command do-plumbing-link-bins
5656
test_util.mock_command do-plumbing-link-completions
@@ -61,7 +61,7 @@ load 'util/init.sh'
6161
run do-link 'package1'
6262

6363
assert_success
64-
assert [ "$(readlink -f $BPM_PACKAGES_PATH/bpm-local/package1)" = "$(readlink -f "$PWD/package1")" ]
64+
assert [ "$(readlink -f $BPM_PACKAGES_PATH/local/package1)" = "$(readlink -f "$PWD/package1")" ]
6565
}
6666

6767
@test "calls link-bins, link-completions, link-man and deps in order" {
@@ -76,10 +76,10 @@ load 'util/init.sh'
7676

7777
assert_success
7878
assert_line -n 0 -e "Linking '/(.*)/bpm/cwd/package2'"
79-
assert_line -n 1 "do-plumbing-add-deps bpm-local/package2"
80-
assert_line -n 2 "do-plumbing-link-bins bpm-local/package2"
81-
assert_line -n 3 "do-plumbing-link-completions bpm-local/package2"
82-
assert_line -n 4 "do-plumbing-link-man bpm-local/package2"
79+
assert_line -n 1 "do-plumbing-add-deps local/package2"
80+
assert_line -n 2 "do-plumbing-link-bins local/package2"
81+
assert_line -n 3 "do-plumbing-link-completions local/package2"
82+
assert_line -n 4 "do-plumbing-link-man local/package2"
8383

8484
}
8585

@@ -95,15 +95,15 @@ load 'util/init.sh'
9595

9696
assert_success
9797
assert_line -n 0 -e "Linking '/(.*)/bpm/cwd/package2'"
98-
assert_line -n 1 "do-plumbing-add-deps bpm-local/package2"
99-
assert_line -n 2 "do-plumbing-link-bins bpm-local/package2"
100-
assert_line -n 3 "do-plumbing-link-completions bpm-local/package2"
101-
assert_line -n 4 "do-plumbing-link-man bpm-local/package2"
98+
assert_line -n 1 "do-plumbing-add-deps local/package2"
99+
assert_line -n 2 "do-plumbing-link-bins local/package2"
100+
assert_line -n 3 "do-plumbing-link-completions local/package2"
101+
assert_line -n 4 "do-plumbing-link-man local/package2"
102102
assert_line -n 5 -e "Linking '/(.*)/bpm/cwd/package3'"
103-
assert_line -n 6 "do-plumbing-add-deps bpm-local/package3"
104-
assert_line -n 7 "do-plumbing-link-bins bpm-local/package3"
105-
assert_line -n 8 "do-plumbing-link-completions bpm-local/package3"
106-
assert_line -n 9 "do-plumbing-link-man bpm-local/package3"
103+
assert_line -n 6 "do-plumbing-add-deps local/package3"
104+
assert_line -n 7 "do-plumbing-link-bins local/package3"
105+
assert_line -n 8 "do-plumbing-link-completions local/package3"
106+
assert_line -n 9 "do-plumbing-link-man local/package3"
107107

108108
}
109109

@@ -119,9 +119,9 @@ load 'util/init.sh'
119119

120120
assert_success
121121
assert_line -n 0 -e "Linking '/(.*)/bpm/cwd/package2'"
122-
assert_line -n 1 "do-plumbing-link-bins bpm-local/package2"
123-
assert_line -n 2 "do-plumbing-link-completions bpm-local/package2"
124-
assert_line -n 3 "do-plumbing-link-man bpm-local/package2"
122+
assert_line -n 1 "do-plumbing-link-bins local/package2"
123+
assert_line -n 2 "do-plumbing-link-completions local/package2"
124+
assert_line -n 3 "do-plumbing-link-man local/package2"
125125
}
126126

127127

@@ -136,7 +136,7 @@ load 'util/init.sh'
136136
run do-link --no-deps 'package2'
137137

138138
assert_success
139-
refute_line "do-plumbing-add-deps bpm-local/package2"
139+
refute_line "do-plumbing-add-deps local/package2"
140140
}
141141

142142
@test "respects the --no-deps option (at end)" {
@@ -150,7 +150,7 @@ load 'util/init.sh'
150150
run do-link 'package2' --no-deps
151151

152152
assert_success
153-
refute_line "do-plumbing-add-deps bpm-local/package2"
153+
refute_line "do-plumbing-add-deps local/package2"
154154
}
155155

156156
@test "links the current directory" {
@@ -165,7 +165,7 @@ load 'util/init.sh'
165165
run do-link .
166166

167167
assert_success
168-
assert [ "$(readlink -f "$BPM_PACKAGES_PATH/bpm-local/package3")" = "$(readlink -f "$PWD")" ]
168+
assert [ "$(readlink -f "$BPM_PACKAGES_PATH/local/package3")" = "$(readlink -f "$PWD")" ]
169169
}
170170

171171
@test "links the parent directory" {
@@ -180,7 +180,7 @@ load 'util/init.sh'
180180
run do-link ..
181181

182182
assert_success
183-
assert [ "$(readlink -f "$BPM_PACKAGES_PATH/bpm-local/sierra")" = "$(readlink -f "$PWD/..")" ]
183+
assert [ "$(readlink -f "$BPM_PACKAGES_PATH/local/sierra")" = "$(readlink -f "$PWD/..")" ]
184184
}
185185

186186
@test "links an arbitrary complex relative path" {
@@ -193,5 +193,5 @@ load 'util/init.sh'
193193
run do-link ./package3/.././package3
194194

195195
assert_success
196-
assert [ "$(readlink -f "$BPM_PACKAGES_PATH/bpm-local/package3")" = "$(readlink -f "$PWD/package3")" ]
196+
assert [ "$(readlink -f "$BPM_PACKAGES_PATH/local/package3")" = "$(readlink -f "$PWD/package3")" ]
197197
}

tests/do-upgrade.bats

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ load 'util/init.sh'
9494
assert [ ! -f "$BPM_INSTALL_BIN/script3.sh" ]
9595
}
9696

97+
@test "prints warning if user tries to upgrade a 'link'ed package" {
98+
test_util.mock_command do-plumbing-add-deps
99+
test_util.mock_command do-plumbing-link-bins
100+
test_util.mock_command do-plumbing-link-completions
101+
test_util.mock_command do-plumbing-link-man
102+
103+
mkdir 'theta'
104+
105+
do-link 'theta'
106+
run 'do-upgrade' 'local/theta'
107+
108+
assert_success
109+
assert_line -p "Package 'github.com/local/theta' has been added with 'bpm link'. It cannot be upgraded"
110+
}
111+
97112
@test "errors when no packages are given" {
98113
run do-upgrade
99114

tests/util/init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export BPM_PACKAGES_PATH="$BPM_PREFIX/packages"
2121
export BPM_INSTALL_BIN="$BPM_PREFIX/bin"
2222
export BPM_INSTALL_MAN="$BPM_PREFIX/man"
2323
export BPM_INSTALL_COMPLETIONS="$BPM_PREFIX/completions"
24+
export BPM_MODE_GLOBAL=
2425

2526
for f in "$BPM_ROOT"/pkg/lib/{commands,util}/?*.sh; do
2627
source "$f"

tests/util/test_util.sh

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,11 @@ test_util.finish_pkg() {
5353
cd "$BPM_CWD"
5454
}
5555

56-
# TODO: use setup_pkg and finish_pkg
5756
test_util.create_package() {
5857
local pkg="$1"
58+
ensure.non_zero 'pkg' "$pkg"
5959

60-
mkdir -p "$BPM_ORIGIN_DIR/github.com/$pkg"
61-
cd "$BPM_ORIGIN_DIR/github.com/$pkg"
62-
63-
git init .
64-
touch 'README.md'
65-
touch 'bpm.toml'
66-
git add .
67-
git commit -m "Initial commit"
68-
69-
cd "$BPM_CWD"
60+
test_util.setup_pkg "$pkg"; {
61+
:
62+
}; test_util.finish_pkg
7063
}

0 commit comments

Comments
 (0)