Skip to content

Commit 56c42ba

Browse files
committed
fix: Show error if some commands are operating in 'local' or 'global'
mode. Closes #67
1 parent eca57d5 commit 56c42ba

File tree

8 files changed

+37
-12
lines changed

8 files changed

+37
-12
lines changed

pkg/lib/commands/do-add.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ do-add() {
3232
esac
3333
done
3434

35+
if [[ "$BPM_IS_LOCAL" == no && "$flag_all" == yes ]]; then
36+
die "Cannot pass '--all' without a 'bpm.toml' file"
37+
fi
38+
3539
if [ "$flag_all" = yes ]; then
3640
local bpm_toml_file="$BPM_ROOT/bpm.toml"
3741

3842
if (( ${#pkgs[@]} > 0 )); then
3943
die "No packages may be supplied when using '--all'"
4044
fi
4145

42-
# TODO: this may be ran under 'global' mode?
4346
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
4447
log.info "Adding all dependencies"
4548

@@ -88,7 +91,6 @@ do-actual-add() {
8891
do-plumbing-link-completions "$site/$package"
8992
do-plumbing-link-man "$site/$package"
9093

91-
# TODO: install for packages.sh
9294
# Install transitive dependencies
9395
local subDep="$BPM_PACKAGES_PATH/$site/$package"
9496

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ do-plumbing-clone() {
99
ensure.non_zero 'uri' "$uri"
1010
ensure.non_zero 'id' "$id"
1111

12-
# TODO this is invalid in the test suite
1312
if [ -e "$BPM_PACKAGES_PATH/$id" ]; then
1413
die "Package '$id' is already present"
1514
fi

pkg/lib/commands/do-upgrade.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ do-upgrade() {
2424
esac
2525
done
2626

27-
if [[ $upgrade_bpm = yes && $flag_all = yes ]]; then
27+
if [[ $upgrade_bpm == yes && "$flag_all" = yes ]]; then
2828
die "Upgrading bpm and using '--all' are mutually exclusive behaviors"
2929
fi
3030

31+
if [[ $upgrade_bpm == yes && "$BPM_IS_LOCAL" == yes ]]; then
32+
die "Cannot upgrade bpm with a local 'bpm.toml' file"
33+
fi
34+
3135
if [ "$upgrade_bpm" = 'yes' ]; then
3236
if (( ${#pkgs[@]} > 0 )); then
3337
die 'Packages cannot be upgraded at the same time as bpm'

pkg/lib/util/abstract-completions.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ abstract.completions_do_action_zsh() {
163163
fi
164164

165165
case "$action" in
166-
link)
166+
link)
167167
if [ -L "$BPM_INSTALL_COMPLETIONS/zsh/compsys/$fileName" ]; then
168-
# TODO: ?
169168
log.error "Skipping '$fileName' since an existing symlink with the same name already exists"
170169
else
171170
mkdir -p "$BPM_INSTALL_COMPLETIONS/zsh/compsys"

tests/do-add.bats

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ load 'util/init.sh'
2828
assert_line -n 0 -p "Cannot install packages owned by username 'local' because that conflicts with linked packages"
2929
}
3030

31-
# TODO: do for link
3231
@test "fails when input is an absolute path to a directory" {
3332
local site='github.com'
3433
local pkg='username/main'
@@ -289,7 +288,7 @@ load 'util/init.sh'
289288
@test "--all prints warning when no dependencies are specified in bpm.toml" {
290289
touch 'bpm.toml'
291290

292-
run do-add --all
291+
BPM_IS_LOCAL='yes' run do-add --all
293292

294293
assert_success
295294
assert_line -p "No dependencies specified in 'dependencies' key"
@@ -299,8 +298,15 @@ load 'util/init.sh'
299298
@test "--all errors when a package is specified as argument" {
300299
touch 'bpm.toml'
301300

302-
run do-add --all pkg
301+
BPM_IS_LOCAL='yes' run do-add --all pkg
303302

304303
assert_failure
305304
assert_line -p "No packages may be supplied when using '--all'"
306305
}
306+
307+
@test "--all errors in global mode" {
308+
run do-add --all
309+
310+
assert_failure
311+
assert_line -p "Cannot pass '--all' without a 'bpm.toml' file"
312+
}

tests/do-plumbing-clone.bats

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
load 'util/init.sh'
44

5-
# TODO: replace output checking with actual cloning using file://
6-
75
@test "installs a specific version" {
86
local site='github.com'
97
local pkg='username/package'
@@ -129,3 +127,10 @@ load 'util/init.sh'
129127
assert_success
130128
assert_line -n 1 "git clone --recursive --depth=1 --single-branch --branch a_branch https://github.com/username/package.git $BPM_PACKAGES_PATH/$site/username/package"
131129
}
130+
131+
@test "--all errors in global mode" {
132+
run do-add --all
133+
134+
assert_failure
135+
assert_line -p "Cannot pass '--all' without a 'bpm.toml' file"
136+
}

tests/do-upgrade.bats

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,19 @@ load 'util/init.sh'
189189
assert_line -p "Upgrading bpm and using '--all' are mutually exclusive behaviors"
190190
}
191191

192+
@test "fail if bpm is specified in local mode" {
193+
touch 'bpm.toml'
194+
195+
BPM_IS_LOCAL='yes' run do-upgrade bpm
196+
197+
assert_failure
198+
assert_line -p "Cannot upgrade bpm with a local 'bpm.toml' file"
199+
}
200+
192201
@test "--all errors when a package is specified as argument" {
193202
touch 'bpm.toml'
194203

195-
run do-remove --all pkg
204+
run do-upgrade --all some/pkg
196205

197206
assert_failure
198207
assert_line -p "No packages may be supplied when using '--all'"

tests/util/init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export BPM_TEST_DIR="$BATS_TMPDIR/bpm"
1717
export BPM_CWD="$BPM_TEST_DIR/cwd"
1818
export BPM_ORIGIN_DIR="$BPM_TEST_DIR/origin"
1919
export BPM_MODE_TEST=
20+
export BPM_IS_LOCAL='no' # normal default is 'yes'
2021

2122
# Stub common variables
2223
test_util.get_bpm_root

0 commit comments

Comments
 (0)