Skip to content

Commit dfdcc44

Browse files
committed
get shellcheck and tests to pass for long opts of verbose and help
1 parent 672430c commit dfdcc44

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

has

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,11 @@ while getopts ":qhv-" OPTION; do
365365
exit 0
366366
;;
367367
-)
368-
[ $OPTIND -ge 1 ] && optind=$((OPTIND - 1)) || optind=$OPTIND
368+
if [ "$OPTIND" -ge 2 ]; then
369+
optind=$((OPTIND - 1))
370+
else
371+
optind=$OPTIND
372+
fi
369373
eval OPTION="\$$optind"
370374
OPTARG=$(echo "$OPTION" | cut -d'=' -f2)
371375
OPTION=$(echo "$OPTION" | cut -d'=' -f1)

tests/unit/unit-tests.bats

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,21 +216,25 @@ teardown() {
216216
[ -z "${output}" ]
217217
}
218218

219-
@test "'has' prints version with --version and -v" {
220-
# run $has --version
221-
# [ "$status" -eq 0 ]
222-
# [[ "${output}" =~ ^has\ version\ [0-9]+\.[0-9]+\.[0-9]+ ]]
219+
@test "'has' prints version with --version" {
220+
run $has --version
221+
[ "$status" -eq 0 ]
222+
[[ "${output}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]
223+
}
223224

225+
@test "'has' prints version with -v" {
224226
run $has -v
225227
[ "$status" -eq 0 ]
226228
[[ "${output}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]
227229
}
228230

229-
@test "'has' prints help with --help and -h" {
230-
# run $has --help
231-
# [ "$status" -eq 0 ]
232-
# [ "${lines[0]}" = 'Usage: has [OPTION] <command-names>...' ]
231+
@test "'has' prints help with --help" {
232+
run $has --help
233+
[ "$status" -eq 0 ]
234+
__assert_usage
235+
}
233236

237+
@test "'has' prints help with -h" {
234238
run $has -h
235239
[ "$status" -eq 0 ]
236240
__assert_usage

0 commit comments

Comments
 (0)