Skip to content

Commit 7d4979c

Browse files
committed
feat: Support upgrading 'bpm' directly from the cli
Previously, a user would have to cd into the directory, then run `git pull` manually. This feature obviates that
1 parent 2059dc0 commit 7d4979c

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

docs/recepies.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ current shell. After installing a package, you can run:
3636
```sh
3737
include username/repo lib/file.sh
3838
```
39+
40+
# Upgrading `bpm`
41+
42+
```sh
43+
bpm upgrade bpm
44+
```

pkg/lib/commands/do-upgrade.sh

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
# shellcheck shell=bash
22

33
do-upgrade() {
4-
if (( $# == 0 )); then
4+
local upgrade_bpm='no'
5+
6+
local -a pkgs=()
7+
for arg; do
8+
case "$arg" in
9+
bpm)
10+
upgrade_bpm='yes'
11+
;;
12+
*)
13+
pkgs+=("$arg")
14+
;;
15+
esac
16+
done
17+
18+
if [ "$upgrade_bpm" = 'yes' ]; then
19+
if (( ${#pkgs[@]} > 0 )); then
20+
die 'You cannot upgarde bpm and its packages at the same time'
21+
fi
22+
23+
if [ -d "$PROGRAM_LIB_DIR/../../.git" ]; then
24+
git -C "$PROGRAM_LIB_DIR/../.." pull
25+
else
26+
log.error "bpm is not a Git repository"
27+
fi
28+
29+
return
30+
fi
31+
32+
if (( ${#pkgs[@]} == 0 )); then
533
die "You must supply at least one package"
634
fi
735

tests/do-upgrade.bats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,32 @@ load 'util/init.sh'
6666

6767
assert [ ! -f "$BPM_INSTALL_BIN/script3.sh" ]
6868
}
69+
70+
@test "errors when no packages are given" {
71+
run do-upgrade
72+
73+
assert_failure
74+
assert_line -p 'You must supply at least one package'
75+
}
76+
77+
@test "upgrade bpm works" {
78+
local pkg='username/package'
79+
80+
test_util.mock_command 'git'
81+
82+
run do-upgrade 'bpm'
83+
84+
assert_success
85+
assert_line 'git -C /home/edwin/data/bpm/source/tests/../pkg/lib/../.. pull'
86+
}
87+
88+
@test "upgrade bpm fails when mixing package names" {
89+
local pkg='username/package'
90+
91+
test_util.mock_command 'git'
92+
93+
run do-upgrade 'bpm' 'pkg/name'
94+
95+
assert_failure
96+
assert_line -p 'You cannot upgarde bpm and its packages at the same time'
97+
}

tests/util/init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export BPM_ORIGIN_DIR="$BPM_TEST_DIR/origin"
1515
export XDG_DATA_HOME=
1616
export PATH="$BPM_ROOT/pkg/bin:$PATH"
1717

18+
export PROGRAM_LIB_DIR="$BATS_TEST_DIRNAME/../pkg/lib"
1819
export BPM_ROOT="$BATS_TEST_DIRNAME/.."
1920
export BPM_PREFIX="$BPM_TEST_DIR/cellar"
2021
export BPM_PACKAGES_PATH="$BPM_PREFIX/packages"

0 commit comments

Comments
 (0)