Skip to content

Commit a17c635

Browse files
committed
feat: Improve output of running commands. Closes #53
1 parent 820493f commit a17c635

12 files changed

+84
-47
lines changed

pkg/lib/commands/do-add.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ do-add() {
3434
die "Cannot install packages owned by username 'local' because that conflicts with linked packages"
3535
fi
3636

37-
log.info "Installing '$repoSpec'"
37+
log.info "Adding '$repoSpec'"
3838
do-plumbing-clone "$uri" "$site/$package" $ref
3939
do-plumbing-add-deps "$site/$package"
4040
do-plumbing-link-bins "$site/$package"

pkg/lib/commands/do-plumbing-add-deps.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ do-plumbing-add-deps() {
2626
fi
2727
fi
2828

29-
log.info "Installing dependencies for '$id'"
29+
if (( ${#deps[@]} > 0 )); then
30+
log.info "Installing dependencies for '$id'"
31+
fi
32+
3033
for dep in "${deps[@]}"; do
3134
do-add "$dep"
3235
done

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ do-plumbing-clone() {
2525
git_args+=("$uri")
2626
git_args+=("$BPM_PACKAGES_PATH/$id")
2727

28-
log.info "Cloning package '$id'"
29-
git clone "${git_args[@]}"
28+
printf '%s\n' " -> Cloning Git repository"
29+
local git_output=
30+
if ! git_output="$(git clone "${git_args[@]}" 2>&1)"; then
31+
log.error "Could not clone repository"
32+
printf "%s" "$git_output"
33+
exit 1
34+
fi
35+
36+
if [ -n "${BPM_MODE_TEST+x}" ]; then
37+
printf "%s" "$git_output"
38+
fi
3039
}

pkg/lib/commands/do-plumbing-remove-deps.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ do-plumbing-remove-deps() {
2020
fi
2121
fi
2222

23-
log.info "Removing dependencies for '$package'"
23+
if (( #${deps[@]} > 0 )); then
24+
log.info "Removing dependencies for '$package'"
25+
fi
26+
2427
for dep in "${deps[@]}"; do
25-
util.extract_data_from_input "$repoSpec" "$with_ssh"
28+
util.extract_data_from_input "$dep"
2629
local site="$REPY2"
2730
local package="$REPLY3"
2831
local ref="$REPLY4"

pkg/lib/commands/do-remove.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ do-remove() {
3939
do_actual_removal() {
4040
local id="$1"
4141

42-
log.info "Uninstalling '$id'"
42+
log.info "Removing '$id'"
4343
do-plumbing-unlink-man "$id"
4444
do-plumbing-unlink-bins "$id"
4545
do-plumbing-unlink-completions "$id"
4646

47-
echo "removing"
48-
47+
printf '%s\n' " -> Deleting Git repository"
48+
echo "${BPM_PACKAGES_PATH:?}/$id"
4949
rm -rf "${BPM_PACKAGES_PATH:?}/$id"
50-
if ! rmdir -p "${BPM_PACKAGES_PATH:?}/$id"; then
50+
if ! rmdir -p "${BPM_PACKAGES_PATH:?}/${id%/*}" &>/dev/null; then
5151
# Do not exit on failure
5252
:
5353
fi

pkg/lib/commands/do-upgrade.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,18 @@ do_actual_upgrade() {
6868
do-plumbing-unlink-bins "$id"
6969
do-plumbing-unlink-completions "$id"
7070
do-plumbing-unlink-man "$id"
71-
git -C "$BPM_PACKAGES_PATH/$id" pull
71+
local git_output=
72+
73+
if ! git_output="$(git -C "$BPM_PACKAGES_PATH/$id" pull 2>&1)"; then
74+
log.error "Could not update Git repository"
75+
printf "%s" "$git_output"
76+
exit 1
77+
fi
78+
79+
if [ -n "${BPM_MODE_TEST+x}" ]; then
80+
printf "%s" "$git_output"
81+
fi
82+
7283
do-plumbing-add-deps "$id"
7384
do-plumbing-link-bins "$id"
7485
do-plumbing-link-completions "$id"

pkg/lib/util/abstract-bins.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
# shellcheck shell=bash
22

3+
abstract_bins_did=no
4+
35
abstract.bins() {
46
local action="$1"
57
local id="$2"
68
ensure.non_zero 'action' "$action"
79
ensure.non_zero 'id' "$id"
810

9-
case "$action" in
10-
link)
11-
log.info "Linking bin files for '$id'"
12-
;;
13-
unlink)
14-
log.info "Unlinking bin files for '$id'"
15-
;;
16-
esac
17-
1811
local -a bins=()
1912
local remove_extension=
2013

@@ -93,6 +86,15 @@ abstract.bins_do_action() {
9386
local fullBinFile="$2"
9487
local remove_extensions="$3"
9588

89+
if [ "$abstract_bins_did" = no ]; then
90+
abstract_bins_did='yes'
91+
92+
case "$action" in
93+
link) printf '%s\n' " -> Linking bin files" ;;
94+
unlink) printf '%s\n' " -> Unlinking bin files" ;;
95+
esac
96+
fi
97+
9698
local binName="${fullBinFile##*/}"
9799

98100
if [[ "${remove_extensions:-no}" == @(yes|true) ]]; then

pkg/lib/util/abstract-completions.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
# shellcheck shell=bash
22

3+
abstract_completions_did=no
4+
35
abstract.completions() {
46
local action="$1"
57
local id="$2"
68
ensure.non_zero 'action' "$action"
79
ensure.non_zero 'id' "$id"
810
ensure.package_exists "$id"
911

10-
case "$action" in
11-
link)
12-
log.info "Linking completion files for '$id'"
13-
;;
14-
unlink)
15-
log.info "Unlinking completion files for '$id'"
16-
;;
17-
esac
18-
1912
local bpm_toml_file="$BPM_PACKAGES_PATH/$id/bpm.toml"
2013
local package_sh_file="$BPM_PACKAGES_PATH/$id/package.sh"
2114

@@ -110,12 +103,13 @@ abstract.completions_do_action_bash() {
110103
local action="$1"
111104
local file="$2"
112105

106+
abstract.completions_do_echo
107+
113108
local fileName="${file##*/}"
114109
if [[ $fileName != *.* ]]; then
115110
fileName="$fileName.bash"
116111
fi
117112

118-
119113
case "$action" in
120114
link)
121115
mkdir -p "$BPM_INSTALL_COMPLETIONS/bash"
@@ -134,6 +128,8 @@ abstract.completions_do_action_zsh() {
134128
local action="$1"
135129
local file="$2"
136130

131+
abstract.completions_do_echo
132+
137133
if grep -qs "^#compdef" "$file"; then
138134
case "$action" in
139135
link)
@@ -165,6 +161,8 @@ abstract.completions_do_action_fish() {
165161
local action="$1"
166162
local file="$2"
167163

164+
abstract.completions_do_echo
165+
168166
case "$action" in
169167
link)
170168
mkdir -p "$BPM_INSTALL_COMPLETIONS/fish"
@@ -177,3 +175,14 @@ abstract.completions_do_action_fish() {
177175
;;
178176
esac
179177
}
178+
179+
abstract.completions_do_echo() {
180+
if [ "$abstract_completions_did" = no ]; then
181+
abstract_completions_did=yes
182+
183+
case "$action" in
184+
link) printf '%s\n' " -> Linking completion files" ;;
185+
unlink) printf '%s\n' " -> Unlinking completion files" ;;
186+
esac
187+
fi
188+
}

pkg/lib/util/abstract-mans.sh

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

3+
abstract_mans_did=no
4+
35
abstract.mans() {
46
local action="$1"
57
local id="$2"
68
ensure.non_zero 'action' "$action"
79
ensure.non_zero 'id' "$id"
810
ensure.package_exists "$id"
911

10-
# TODO: only print when actually linking
11-
case "$action" in
12-
link)
13-
log.info "Linking man files for '$id'"
14-
;;
15-
unlink)
16-
log.info "Unlinking man files for '$id'"
17-
;;
18-
esac
19-
2012
local bpm_toml_file="$BPM_PACKAGES_PATH/$id/bpm.toml"
2113

2214
if [ -f "$bpm_toml_file" ]; then
@@ -79,6 +71,15 @@ abstract.mans_do_action() {
7971
if [[ "$full_man_file" =~ $regex ]]; then
8072
local n="${BASH_REMATCH[1]}"
8173

74+
if [ "$abstract_mans_did" = no ]; then
75+
abstract_mans_did=yes
76+
77+
case "$action" in
78+
link) printf '%s\n' " -> Linking man files" ;;
79+
unlink) printf '%s\n' " -> Unlinking man files" ;;
80+
esac
81+
fi
82+
8283
case "$action" in
8384
link)
8485
mkdir -p "$BPM_INSTALL_MAN/man$n"

tests/do-add.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ load 'util/init.sh'
5555
run do-add username/package
5656

5757
assert_success
58-
assert_line -n 0 -p "Installing 'username/package'"
58+
assert_line -n 0 -p "Adding 'username/package'"
5959
assert_line -n 1 'do-plumbing-clone https://github.com/username/package.git github.com/username/package'
6060
assert_line -n 2 'do-plumbing-add-deps github.com/username/package'
6161
assert_line -n 3 'do-plumbing-link-bins github.com/username/package'
@@ -73,13 +73,13 @@ load 'util/init.sh'
7373
run do-add username/package username2/package2
7474

7575
assert_success
76-
assert_line -n 0 -p "Installing 'username/package'"
76+
assert_line -n 0 -p "Adding 'username/package'"
7777
assert_line -n 1 'do-plumbing-clone https://github.com/username/package.git github.com/username/package'
7878
assert_line -n 2 'do-plumbing-add-deps github.com/username/package'
7979
assert_line -n 3 'do-plumbing-link-bins github.com/username/package'
8080
assert_line -n 4 'do-plumbing-link-completions github.com/username/package'
8181
assert_line -n 5 'do-plumbing-link-man github.com/username/package'
82-
assert_line -n 6 -p "Installing 'username2/package2'"
82+
assert_line -n 6 -p "Adding 'username2/package2'"
8383
assert_line -n 7 'do-plumbing-clone https://github.com/username2/package2.git github.com/username2/package2'
8484
assert_line -n 8 'do-plumbing-add-deps github.com/username2/package2'
8585
assert_line -n 9 'do-plumbing-link-bins github.com/username2/package2'

0 commit comments

Comments
 (0)