aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-02-01 09:28:18 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-02-01 09:28:18 +0100
commit97036aeae73cc2a63219c7b792ab5f18c7d98cd1 (patch)
treeb71a4e0ebde196ad7b4858f4dbaf499b7b3b7201
parent537935edab2e847196a46be68956c8ed2300a22a (diff)
downloadapp.sh-97036aeae73cc2a63219c7b792ab5f18c7d98cd1.tar.gz
app.sh-97036aeae73cc2a63219c7b792ab5f18c7d98cd1.tar.bz2
app.sh-97036aeae73cc2a63219c7b792ab5f18c7d98cd1.tar.xz
app.sh-97036aeae73cc2a63219c7b792ab5f18c7d98cd1.zip
libexec/app-resolver-maven: Better argument checking.
lib/common: Starting a way to have a common usage/help semantics.
-rw-r--r--NOTES.tmp11
-rwxr-xr-xbin/app-init19
-rwxr-xr-xlib/common15
-rwxr-xr-xlibexec/app-resolver-maven31
4 files changed, 48 insertions, 28 deletions
diff --git a/NOTES.tmp b/NOTES.tmp
index 5798e61..7ecab9c 100644
--- a/NOTES.tmp
+++ b/NOTES.tmp
@@ -19,3 +19,14 @@ app list - lists all applications available under the specified directory
TODO:
* tab => spaces
* camelCase => snake_case
+* Figure out the versions of bash that's available in the different
+ major operating systems:
+ * Debian
+ * Ubuntu
+ * RedHat
+ * SLES/OpenSuse
+ * Cygwin
+* Document patterns for parsing command line arguments
+* Support sending in config to an app when running init. Has to be
+ installed before running the hooks, useful to controlling
+ environment through config.
diff --git a/bin/app-init b/bin/app-init
index 018b210..ba97ebd 100755
--- a/bin/app-init
+++ b/bin/app-init
@@ -8,14 +8,8 @@ APPSH_HOME=$(cd $(dirname "$0")/.. && pwd)
. $APPSH_HOME/lib/common
# HEADER END
-usage() {
- echo "usage: $0 -d dir <resolver> <resolver args>"
- exit 1
-}
-
-fatal() {
- echo "$0: $@"
- exit 1
+usage_inner() {
+ echo "usage: $usage_app -d dir <resolver> <resolver args>"
}
while getopts "d:" opt
@@ -46,8 +40,6 @@ then
fatal "Already initialized: $dir" 2>&1
fi
-# TODO: install a trap handler and rm -rf "$dir"
-
resolver=`grep_path "/app-resolver-$resolver_name$" "$PATH" | head -n 1`
if [ -z "$resolver" ]
@@ -57,6 +49,11 @@ then
fi
mkdir -p -- "$dir" "$dir/.app"
+
+ok=no
+clean_dir=`cd "$dir">/dev/null; pwd`
+trap '[[ $ok == yes ]] || rm -rf "$clean_dir"' EXIT
+
cd "$dir"
app-conf set app.resolver "$resolver_name"
@@ -77,3 +74,5 @@ echo "Resolved version to $version"
"$resolver" download-version -v "$version" -f .app/latest.zip
app-install-file -v "$version" -f .app/latest.zip
+
+ok=yes
diff --git a/lib/common b/lib/common
index e90f77b..63f712a 100755
--- a/lib/common
+++ b/lib/common
@@ -40,6 +40,21 @@ assert_is_app() {
fi
}
+usage() {
+ message=${1-}
+
+ if [[ $message != "" ]]
+ then
+ echo $message
+ fi
+
+ if [ "`declare -f usage_inner >/dev/null; echo $?`" = 0 ]
+ then
+ usage_inner >&2
+ fi
+ exit 1
+}
+
debug() {
[[ $echo_debug == no ]] || echo "D: $usage_app: $@" 2>&1
}
diff --git a/libexec/app-resolver-maven b/libexec/app-resolver-maven
index a3b367c..81e85ab 100755
--- a/libexec/app-resolver-maven
+++ b/libexec/app-resolver-maven
@@ -8,18 +8,10 @@ APPSH_HOME=$(cd $(dirname "$0")/.. && pwd)
. $APPSH_HOME/lib/common
# HEADER END
-usage() {
- message=${1-}
-
- if [ ! -z "$message" ]
- then
- echo $message
- fi
-
- echo "usage: $subapp init -r <repo> <maven url>"
- echo "usage: $subapp resolve-version"
- echo "usage: $subapp download-version -v <version> -f <download target>"
- exit 1
+usage_inner() {
+ echo "usage: $usage_app init -r <repo> <maven url>"
+ echo "usage: $usage_app resolve-version"
+ echo "usage: $usage_app download-version -v <version> -f <download target>"
}
slash() {
@@ -201,22 +193,25 @@ init() {
esac
done
- x=`echo $1 | tr ":" " "`; set -- $x
- group_id=$1
- artifact_id=$2
- version=$3
+ local coordinates=${1-}
+ x=${coordinates}
+ x=${x//:/ }
+ set -- $x
- if [ -z "$group_id" -o -z "$artifact_id" -o -z "$version" ]
+ if [[ $# != 3 || $1 == "" || $2 == "" || $3 == "" ]]
then
usage "Invalid Maven coordinates: $coordinates"
fi
+ group_id=$1
+ artifact_id=$2
+ version=$3
+
app-conf set maven.group_id "$group_id"
app-conf set maven.artifact_id "$artifact_id"
app-conf set maven.version "$version"
}
-subapp="$0";
command="$1"; shift
case "$command" in