Skip to content

Commit c5317f5

Browse files
committed
fix: Improve error messages
This partly addresses #61
1 parent 44889ac commit c5317f5

15 files changed

+75
-54
lines changed

pkg/lib/commands/do-add.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ do-add() {
3636
local bpm_toml_file="$BPM_ROOT/bpm.toml"
3737

3838
if (( ${#pkgs[@]} > 0 )); then
39-
die "You must not supply any packages when using '--all'"
39+
die "No packages may be supplied when using '--all'"
4040
fi
4141

4242
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then

pkg/lib/commands/do-link.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ do-link() {
2121
done
2222

2323
if (( ${#dirs[@]} == 0 )); then
24-
die "You must supply at least one directory"
24+
die 'At least one package must be supplied'
2525
fi
2626

2727
for dir in "${dirs[@]}"; do

pkg/lib/commands/do-list.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ do-list() {
104104
done
105105

106106
if [ "$has_invalid_packages" = 'yes' ]; then
107-
log.error "You have invalid packages. To fix this optimally, remove the '${BPM_PACKAGES_PATH%/*}' directory and reinstall all that packages that were deleted in the process. This procedure is required in response to a one-time breaking change in how packages are stored"
107+
log.error "Some packages are installed in an outdated format. To fix this optimally, remove the '${BPM_PACKAGES_PATH%/*}' directory and reinstall all the packages that were deleted in the process. This procedure is required in response to a one-time breaking change in how packages are stored"
108108
fi
109109
}

pkg/lib/commands/do-package-path.sh

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

33
bpm-package-path() {
44
local id="$1"
5-
ensure.non_zero 'id' "$id"
5+
6+
if [ -z "$id" ]; then
7+
die "No package specified"
8+
fi
69

710
util.setup_mode
811

@@ -15,6 +18,6 @@ bpm-package-path() {
1518
if [ -d "$dir" ]; then
1619
printf "%s\n" "$dir"
1720
else
18-
die "Package '$site/$package' not found"
21+
die "Package '$site/$package' is not installed"
1922
fi
2023
}

pkg/lib/commands/do-remove.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ do-remove() {
2424
local bpm_toml_file="$BPM_ROOT/bpm.toml"
2525

2626
if (( ${#pkgs[@]} > 0 )); then
27-
die "You must not supply any packages when using '--all'"
27+
die "No packages may be supplied when using '--all'"
2828
fi
2929

3030
if util.get_toml_array "$bpm_toml_file" 'dependencies'; then
@@ -41,7 +41,7 @@ do-remove() {
4141
fi
4242

4343
if (( ${#pkgs[@]} == 0 )); then
44-
die "You must supply at least one package"
44+
die "At least one package must be supplied"
4545
fi
4646

4747
for repoSpec in "${pkgs[@]}"; do

pkg/lib/commands/do-upgrade.sh

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ do-upgrade() {
2222

2323
if [ "$upgrade_bpm" = 'yes' ]; then
2424
if (( ${#pkgs[@]} > 0 )); then
25-
die 'You cannot upgarde bpm and its packages at the same time'
25+
die 'Packages cannot be upgraded at the same time as bpm'
2626
fi
2727

2828
if [ -d "$PROGRAM_LIB_DIR/../../.git" ]; then
@@ -35,30 +35,27 @@ do-upgrade() {
3535
fi
3636

3737
if (( ${#pkgs[@]} == 0 )); then
38-
die "You must supply at least one package"
38+
die "At least one package must be supplied"
3939
fi
4040

4141
for repoSpec; do
42-
if [[ -d "$repoSpec" && "${repoSpec::1}" == / ]]; then
43-
die "Identifier '$repoSpec' is a directory, not a package"
44-
fi
45-
4642
util.extract_data_from_input "$repoSpec"
4743
local site="$REPLY2"
4844
local package="$REPLY3"
49-
local ref="$REPLY4"
5045

51-
do_actual_upgrade "$site/$package"
46+
if [ -L "$BPM_PACKAGES_PATH/$site/$package" ]; then
47+
die "Package '$site/$package' is locally symlinked and cannot be upgraded through Git"
48+
elif [ -d "$BPM_PACKAGES_PATH/$site/$package" ]; then
49+
do_actual_upgrade "$site/$package"
50+
else
51+
die "Package '$site/$package' is not installed"
52+
fi
5253
done
5354
}
5455

5556
do_actual_upgrade() {
5657
local id="$1"
5758

58-
if [ ! -d "$BPM_PACKAGES_PATH/$id/.git" ]; then
59-
die "Package at '$BPM_PACKAGES_PATH/$id' is not a Git repository"
60-
fi
61-
6259
log.info "Upgrading '$id'"
6360
do-plumbing-remove-deps "$id"
6461
do-plumbing-unlink-bins "$id"

pkg/lib/util/ensure.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ ensure.package_exists() {
3939
die "Package '$id' does not exist"
4040
fi
4141
}
42+
43+
ensure.not_absolute_path() {
44+
local path="$1"
45+
46+
if [ "${path::1}" = / ]; then
47+
die "Path '$path' is not absolute"
48+
fi
49+
}

pkg/lib/util/util.sh

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -264,27 +264,20 @@ util.get_project_root_dir() {
264264
printf "%s" "$PWD"
265265
}
266266

267-
util.set_bpm_variables() {
268-
local project_root_dir="$1"
269-
ensure.non_zero 'project_root_dir' "$project_root_dir"
270-
271-
BPM_ROOT="$project_root_dir"
272-
BPM_PREFIX="$project_root_dir/bpm_packages"
273-
BPM_PACKAGES_PATH="$BPM_PREFIX/packages"
274-
BPM_INSTALL_BIN="$BPM_PREFIX/bin"
275-
BPM_INSTALL_MAN="$BPM_PREFIX/man"
276-
BPM_INSTALL_COMPLETIONS="$BPM_PREFIX/completions"
277-
}
278-
279267
# @description Sets up the variables for the current mode
280268
util.setup_mode() {
281269
if [ "$BPM_IS_LOCAL" = yes ]; then
282270
local project_root_dir=
283-
if ! project_root_dir="$(util.get_project_root_dir)"; then
271+
if project_root_dir="$(util.get_project_root_dir)"; then
272+
BPM_ROOT="$project_root_dir"
273+
BPM_PREFIX="$project_root_dir/bpm_packages"
274+
BPM_PACKAGES_PATH="$BPM_PREFIX/packages"
275+
BPM_INSTALL_BIN="$BPM_PREFIX/bin"
276+
BPM_INSTALL_MAN="$BPM_PREFIX/man"
277+
BPM_INSTALL_COMPLETIONS="$BPM_PREFIX/completions"
278+
else
284279
die "No 'bpm.toml' file found"
285280
fi
286-
287-
util.set_bpm_variables "$project_root_dir"
288281
else
289282
# If we do not set local mode, the default varaible
290283
# values are already correct
@@ -299,7 +292,7 @@ Usage:
299292
300293
Subcommands:
301294
init <shell>
302-
Configure shell environment for Basher
295+
Configure shell environment for bpm
303296
304297
add [--ssh] [--branch=<name>] [--all] [[site/]<package>[@ref]...]
305298
Installs a package from GitHub (or a custom site)
@@ -311,18 +304,15 @@ Subcommands:
311304
Uninstalls a package
312305
313306
link [--no-deps] <directory...>
314-
Installs a local directory as a bpm package. These show up with
315-
a namespace of 'local'
307+
Installs a package from a local directory. These have a
308+
namespace of 'local'
316309
317310
list [--simple] [--fetch]
318311
List installed packages
319312
320313
package-path <package>
321314
Outputs the path for a package
322315
323-
complete <command...>
324-
Perform the completion for a particular subcommand. Used by the completion scripts
325-
326316
Examples:
327317
bpm add tj/git-extras
328318
bpm add github.com/tj/git-extras

tests/do-add.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,5 +301,5 @@ load 'util/init.sh'
301301
run do-add --all pkg
302302

303303
assert_failure
304-
assert_line -p "You must not supply any packages when using '--all'"
304+
assert_line -p "No packages may be supplied when using '--all'"
305305
}

tests/do-link.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,10 @@ load 'util/init.sh'
247247
assert_success
248248
assert [ "$(readlink -f "$BPM_PACKAGES_PATH/local/$dir")" = "$(readlink -f "$BPM_ORIGIN_DIR/parent/$dir")" ]
249249
}
250+
251+
@test "errors when no packages are given" {
252+
run do-link
253+
254+
assert_failure
255+
assert_line -p 'At least one package must be supplied'
256+
}

0 commit comments

Comments
 (0)