Skip to content

Commit ca19b9d

Browse files
committed
feat: Add --all flags to install all packages for a particular project. Closes #47
It does this by reading the 'dependencies' key in bpm.toml and installing those one after another
1 parent 5411af1 commit ca19b9d

File tree

6 files changed

+102
-6
lines changed

6 files changed

+102
-6
lines changed

pkg/lib/commands/do-add.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
11
# shellcheck shell=bash
22

33
do-add() {
4-
local with_ssh='no'
4+
local with_ssh='no' # TODO: refactor flag_
5+
local flag_all='no'
56

67
local -a pkgs=()
78
for arg; do
89
case "$arg" in
910
--ssh)
1011
with_ssh='yes'
1112
;;
13+
--all)
14+
flag_all='yes'
15+
;;
1216
*)
1317
pkgs+=("$arg")
1418
;;
1519
esac
1620
done
1721

22+
if [ "$flag_all" = yes ]; then
23+
local bpm_toml_file="$BPM_ROOT/bpm.toml"
24+
25+
if (( ${#pkgs[@]} > 0 )); then
26+
die "You must not supply any packages when using '--all'"
27+
fi
28+
29+
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
30+
log.info "Adding all dependencies"
31+
32+
for pkg in "${REPLIES[@]}"; do
33+
do-add "$pkg"
34+
done
35+
else
36+
log.warn "No dependencies specified in 'dependencies' key"
37+
fi
38+
39+
return
40+
fi
41+
1842
if (( ${#pkgs[@]} == 0 )); then
1943
die "At least one package must be supplied"
2044
fi

pkg/lib/commands/do-remove.sh

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
11
# shellcheck shell=bash
22

33
do-remove() {
4-
if (( $# == 0 )); then
4+
local flag_all='no'
5+
6+
local -a pkgs=()
7+
for arg; do
8+
case "$arg" in
9+
--all)
10+
flag_all='yes'
11+
;;
12+
*)
13+
pkgs+=("$arg")
14+
;;
15+
esac
16+
done
17+
18+
if [ "$flag_all" = yes ]; then
19+
local bpm_toml_file="$BPM_ROOT/bpm.toml"
20+
21+
if (( ${#pkgs[@]} > 0 )); then
22+
die "You must not supply any packages when using '--all'"
23+
fi
24+
25+
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
26+
log.info "Removing all dependencies"
27+
28+
for pkg in "${REPLIES[@]}"; do
29+
do-remove "$pkg"
30+
done
31+
else
32+
log.warn "No dependencies specified in 'dependencies' key"
33+
fi
34+
35+
return
36+
fi
37+
38+
if (( ${#pkgs[@]} == 0 )); then
539
die "You must supply at least one package"
640
fi
741

8-
for repoSpec; do
42+
for repoSpec in "${pkgs[@]}"; do
943
util.extract_data_from_input "$repoSpec"
1044
local site="$REPLY2"
1145
local package="$REPLY3"

pkg/lib/util/abstract-completions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ abstract.completions_do_action_fish() {
200200
case "$action" in
201201
link)
202202
if [ -L "$BPM_INSTALL_COMPLETIONS/fish/${file##*/}" ]; then
203-
log.error "Skipping '$fileName' since an existing symlink with the same name already exists"
203+
log.error "Skipping '$fileName' since an existing symlink with the same name already exists"
204204
else
205205
mkdir -p "$BPM_INSTALL_COMPLETIONS/fish"
206206
ln -sf "$file" "$BPM_INSTALL_COMPLETIONS/fish/${file##*/}"

pkg/lib/util/util.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ Subcommands:
258258
init <shell>
259259
Configure shell environment for Basher
260260
261-
add [--ssh] [[site/]<package>[@ref]...]
261+
add [--ssh] [--all] [[site/]<package>[@ref]...]
262262
Installs a package from GitHub (or a custom site)
263263
264-
remove <package...>
264+
remove [--all] <package...>
265265
Uninstalls a package
266266
267267
link [--no-deps] <directory...>

tests/do-add.bats

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,22 @@ load 'util/init.sh'
204204
assert_success
205205
assert_line "do-plumbing-clone https://github.com/username/package.git github.com/username/package"
206206
}
207+
208+
@test "--all prints warning when no dependencies are specified in bpm.toml" {
209+
touch 'bpm.toml'
210+
211+
run do-add --all
212+
213+
assert_success
214+
assert_line -p "No dependencies specified in 'dependencies' key"
215+
refute_line -p "Installing"
216+
}
217+
218+
@test "--all errors when a package is specified as argument" {
219+
touch 'bpm.toml'
220+
221+
run do-add --all pkg
222+
223+
assert_failure
224+
assert_line -p "You must not supply any packages when using '--all'"
225+
}

tests/do-remove.bats

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,22 @@ load 'util/init.sh'
156156
assert [ -d "$BPM_PACKAGES_PATH/$site/$pkg2" ]
157157
assert [ -e "$BPM_INSTALL_BIN/exec2" ]
158158
}
159+
160+
@test "--all prints warning when no dependencies are specified in bpm.toml" {
161+
touch 'bpm.toml'
162+
163+
run do-remove --all
164+
165+
assert_success
166+
assert_line -p "No dependencies specified in 'dependencies' key"
167+
refute_line -p "Installing"
168+
}
169+
170+
@test "--all errors when a package is specified as argument" {
171+
touch 'bpm.toml'
172+
173+
run do-remove --all pkg
174+
175+
assert_failure
176+
assert_line -p "You must not supply any packages when using '--all'"
177+
}

0 commit comments

Comments
 (0)