Skip to content

Commit 12411da

Browse files
committed
feat: More flexible parse command line arguments. Closes #15
Now, options can be placed after or in between directories or package identifiers
1 parent b8fefd5 commit 12411da

File tree

7 files changed

+60
-34
lines changed

7 files changed

+60
-34
lines changed

pkg/lib/cmd/bpm.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,52 +37,42 @@ main() {
3737
complete)
3838
shift
3939
do-complete "$@"
40-
exit
4140
;;
4241
echo)
4342
shift
4443
do-echo "$@"
45-
exit
4644
;;
4745
init)
4846
shift
4947
do-init "$@"
50-
exit
5148
;;
5249
install)
5350
shift
5451
do-install "$@"
55-
exit
5652
;;
5753
link)
5854
shift
5955
do-link "$@"
60-
exit
6156
;;
6257
list)
6358
shift
6459
do-list "$@"
65-
exit
6660
;;
6761
outdated)
6862
shift
6963
bpm-outdated "$@"
70-
exit
7164
;;
7265
package-path)
7366
shift
7467
bpm-package-path "$@"
75-
exit
7668
;;
7769
uninstall)
7870
shift
7971
do-uninstall "$@"
80-
exit
8172
;;
8273
upgrade)
8374
shift
8475
do-upgrade "$@"
85-
exit
8676
;;
8777
*)
8878
if [ -n "$1" ]; then

pkg/lib/commands/do-install.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
do-install() {
44
local with_ssh='no'
55

6-
case "$1" in
6+
local -a pkgs=()
7+
for arg; do
8+
case "$arg" in
79
--ssh)
810
with_ssh='yes'
9-
shift
10-
;;
11-
esac
11+
;;
12+
*)
13+
pkgs+=("$arg")
14+
;;
15+
esac
16+
done
1217

13-
if (( $# == 0 )); then
18+
if (( ${#pkgs[@]} == 0 )); then
1419
die "At least one package must be supplied"
1520
fi
1621

17-
for repoSpec; do
22+
for repoSpec in "${pkgs[@]}"; do
1823
util.construct_clone_url "$repoSpec" "$with_ssh"
1924
local uri="$REPLY1"
2025
local package="$REPLY2"

pkg/lib/commands/do-link.sh

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

33
do-link() {
4-
if (( $# == 0 )); then
5-
die "You must supply at least one directory"
6-
fi
7-
84
local install_deps='yes'
95

10-
case "$1" in
11-
--no-deps)
12-
install_deps='no'
13-
shift
14-
;;
15-
esac
6+
local -a dirs=()
7+
for arg; do
8+
case "$arg" in
9+
--no-deps)
10+
install_deps='no'
11+
;;
12+
*)
13+
dirs+=("$arg")
14+
;;
15+
esac
16+
done
17+
18+
if (( ${#dirs[@]} == 0 )); then
19+
die "You must supply at least one directory"
20+
fi
1621

17-
for directory; do
22+
for directory in "${dirs[@]}"; do
1823
if [ ! -d "$directory" ]; then
1924
die "Directory '$directory' not found"
2025
fi

pkg/lib/commands/do-list.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ do-list() {
77
case "$arg" in
88
--outdated)
99
should_show_outdated='yes'
10-
shift
1110
;;
1211
esac
1312
done

pkg/lib/util/util.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ util.construct_clone_url() {
8383
site="github.com"
8484
package="$repoSpec"
8585
else
86-
die "Invalid repository"
86+
die "Invalid repository '$repoSpec'"
8787
fi
8888

8989
if [[ "$package" = *@* ]]; then
@@ -234,13 +234,13 @@ Subcommands:
234234
init <shell>
235235
Configure shell environment for Basher
236236
237-
install [--ssh] [site]/<package>[@ref]
237+
install [--ssh] [[site/]<package>[@ref]...]
238238
Installs a package from GitHub (or a custom site)
239239
240-
uninstall <package>
240+
uninstall <package...>
241241
Uninstalls a package
242242
243-
link [--no-deps] <directory>
243+
link [--no-deps] <directory...>
244244
Installs a local directory as a bpm package. These show up with
245245
a namespace of 'bpm-local'
246246
@@ -250,10 +250,10 @@ Subcommands:
250250
package-path <package>
251251
Outputs the path for a package
252252
253-
upgrade <package>
253+
upgrade <package...>
254254
Upgrades a package
255255
256-
complete <command>
256+
complete <command...>
257257
Perform the completion for a particular subcommand. Used by the completion scripts
258258
259259
Examples:

tests/do-install.bats

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ load 'util/init.sh'
123123
assert_line "do-plumbing-clone git@github.com:username/package.git username/package"
124124
}
125125

126+
@test "uses ssh protocol, when specified (at end)" {
127+
test_util.mock_command do-plumbing-clone
128+
test_util.mock_command do-plumbing-add-deps
129+
test_util.mock_command do-plumbing-link-bins
130+
test_util.mock_command do-plumbing-link-completions
131+
test_util.mock_command do-plumbing-link-man
132+
133+
run do-install username/package --ssh
134+
135+
assert_success
136+
assert_line "do-plumbing-clone git@github.com:username/package.git username/package"
137+
}
138+
126139
@test "uses ssh protocol raw, when specified" {
127140
test_util.mock_command do-plumbing-clone
128141
test_util.mock_command do-plumbing-add-deps

tests/do-link.bats

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ load 'util/init.sh'
139139
refute_line "do-plumbing-add-deps bpm-local/package2"
140140
}
141141

142+
@test "respects the --no-deps option (at end)" {
143+
test_util.mock_command do-plumbing-add-deps
144+
test_util.mock_command do-plumbing-link-bins
145+
test_util.mock_command do-plumbing-link-completions
146+
test_util.mock_command do-plumbing-link-man
147+
148+
mkdir 'package2'
149+
150+
run do-link 'package2' --no-deps
151+
152+
assert_success
153+
refute_line "do-plumbing-add-deps bpm-local/package2"
154+
}
155+
142156
@test "links the current directory" {
143157
test_util.mock_command do-plumbing-add-deps
144158
test_util.mock_command do-plumbing-link-bins

0 commit comments

Comments
 (0)