diff options
-rw-r--r-- | .app/lib/app-app | 13 | ||||
-rwxr-xr-x | app | 16 | ||||
-rw-r--r-- | test/01-help.bats | 33 |
3 files changed, 57 insertions, 5 deletions
diff --git a/.app/lib/app-app b/.app/lib/app-app index 30d2007..130244e 100644 --- a/.app/lib/app-app +++ b/.app/lib/app-app @@ -6,7 +6,7 @@ then else repo="http://repo1.maven.org" fi - + # TODO: support file:// repositories # TODO: look in the local repository first # TODO: assert that we got a 200 OK @@ -420,10 +420,10 @@ method_app_usage() { method_app() { local name="$1"; shift local instance="$1"; shift + local method="$1" if [ $# -gt 0 ] then - method=$1 shift fi @@ -432,7 +432,14 @@ method_app() { list) method_list "$name" "$instance" "$@" ;; list-versions) method_list_versions "$name" "$instance" "$@" ;; set-current) method_set_current "$name" "$instance" "$@" ;; - *) method_app_usage "Unknown method $method" ;; + *) + if [ -z "$method" ] + then + method_app_usage + else + method_app_usage "Unknown method $method" + fi + ;; esac exit $? } @@ -13,6 +13,11 @@ mkdir -p $BASEDIR/.app/var/pid mkdir -p $BASEDIR/.app/var/download method_usage() { + if [ -n "$1" ] + then + echo "Error:" "$@" >&2 + fi + echo "usage: $0 [-n name] [-i instance] <method group>" >&2 echo "" >&2 echo "Available method groups:" >&2 @@ -78,9 +83,9 @@ main() { esac done + local method=$1 if [ $# -gt 0 ] then - method=$1 shift fi @@ -88,7 +93,14 @@ main() { app) method_app "$name" "$instance" "$@" ;; conf) method_conf "$name" "$instance" "$@" ;; operate) method_operate "$name" "$instance" "$@" ;; - *) method_usage ;; + *) + if [ -z "$method" ] + then + method_usage + else + method_usage "No such method group: $method" + fi + ;; esac exit $? } diff --git a/test/01-help.bats b/test/01-help.bats new file mode 100644 index 0000000..7d38592 --- /dev/null +++ b/test/01-help.bats @@ -0,0 +1,33 @@ +#!/bin/bash + +workdir=test-run + +# TODO: assert that the exit code is 1 for 'usage' outputs. +exit_usage=0 + +setup() { + rm -rf $workdir +} + +echo_lines() { + for line in "${lines[@]}"; do echo $line; done +} + +@test "./app" { + run ./app; echo_lines + [ $status -eq $exit_usage ] + [ $(expr "${lines[0]}" : "usage: ./app .*") -ne 0 ] +} + +@test "./app foo" { + run ./app foo; echo_lines + [ $status -eq $exit_usage ] + [ "${lines[0]}" = "Error: No such method group: foo" ] + [ $(expr "${lines[1]}" : "usage: ./app .*") -ne 0 ] +} + +@test "./app app" { + run ./app app; echo_lines + [ $status -eq $exit_usage ] + [ $(expr "${lines[0]}" : "usage: ./app app .*") -ne 0 ] +} |