aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-10-16 23:57:41 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-10-16 23:57:41 +0200
commita3ce3f7eabbb746aa9ced430bcd55391742c738b (patch)
treee4dcab1586b725508a57bfce83f3067a95b26a89
parentf563dc165ce1ee8747eea647231bf8e295d8af3f (diff)
downloadapp.sh-a3ce3f7eabbb746aa9ced430bcd55391742c738b.tar.gz
app.sh-a3ce3f7eabbb746aa9ced430bcd55391742c738b.tar.bz2
app.sh-a3ce3f7eabbb746aa9ced430bcd55391742c738b.tar.xz
app.sh-a3ce3f7eabbb746aa9ced430bcd55391742c738b.zip
o Improved completion (again).
o Consistent usage of APPSH_HOME and BASEDIR.
-rw-r--r--.app/lib/app-operate7
-rwxr-xr-x.app/lib/pid-method2
-rw-r--r--app_completion56
-rw-r--r--docs/README.md25
-rw-r--r--test/data/app-a/root/bin/app-a9
-rw-r--r--test/data/app-a/root/etc/app.conf1
-rwxr-xr-xtest/it-install-remove.bats25
-rw-r--r--test/utils.bash3
8 files changed, 109 insertions, 19 deletions
diff --git a/.app/lib/app-operate b/.app/lib/app-operate
index d2f3a00..7789939 100644
--- a/.app/lib/app-operate
+++ b/.app/lib/app-operate
@@ -27,7 +27,7 @@ run_control() {
if [ -z "$bin" ]
then
- bin=$BASEDIR/.app/lib/pid-method
+ bin=$APPSH_HOME/.app/lib/pid-method
fi
if [ ! -x "$bin" ]
@@ -45,6 +45,7 @@ run_control() {
$e \
APPSH_METHOD=$method \
APPSH_BASEDIR=$BASEDIR \
+ APPSH_HOME=$APPSH_HOME \
APPSH_NAME=$name \
APPSH_INSTANCE=$instance \
$bin
@@ -54,10 +55,10 @@ run_control() {
case $ret in
0)
- echo "Application ${method}ed"
+ echo "Method ${method} completed successfully for $name/$instance"
;;
*)
- echo "Error ${method}ing $name/$instance"
+ echo "Error running method ${method} for $name/$instance"
;;
esac
)
diff --git a/.app/lib/pid-method b/.app/lib/pid-method
index e718849..b4a672e 100755
--- a/.app/lib/pid-method
+++ b/.app/lib/pid-method
@@ -4,7 +4,7 @@ set -e
PID_FILE=$APPSH_BASEDIR/.app/var/pid/$name-$instance.pid
-. $APPSH_BASEDIR/.app/lib/app-conf
+. $APPSH_HOME/.app/lib/app-conf
bin=`get_conf $APPSH_BASEDIR $APPSH_NAME $APPSH_INSTANCE app.bin`
diff --git a/app_completion b/app_completion
index c4bfe02..fd25f66 100644
--- a/app_completion
+++ b/app_completion
@@ -1,16 +1,25 @@
#!/bin/bash
-_appsh_contains() {
+_appsh_find() {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && echo $1 && return; done
}
-_appsh_methods=(
+_appsh_method_groups=(
"instance"
"conf"
"operate"
)
+_appsh_methods=(
+ "install"
+ )
+
+_appsh_resolvers=(
+ "file"
+ "maven"
+ )
+
_appsh_parse_opts() {
local prev=""
local has_method
@@ -24,9 +33,11 @@ _appsh_parse_opts() {
echo "local has_i=$curr"
fi
- has_method="$has_method$(_appsh_contains "$curr" ${_appsh_methods[@]})"
+ has_method_group="$has_method_group$(_appsh_find "$curr" ${_appsh_method_groups[@]})"
+ has_method="$has_method$(_appsh_find "$curr" ${_appsh_methods[@]})"
prev="${COMP_WORDS[$i]}"
done
+ echo "local has_method_group='$has_method_group'"
echo "local has_method='$has_method'"
case "${COMP_WORDS[COMP_CWORD]}" in
@@ -42,11 +53,13 @@ _complete_appsh() {
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local opts=""
- eval `_appsh_parse_opts`
+ local x=`_appsh_parse_opts`
+ eval "$x"
+# set | grep ^has_
if [ $COMP_CWORD == 1 ]
then
- opts="${_appsh_methods[@]}"
+ opts="${_appsh_method_groups[@]}"
opts="$opts"
if [ "$in_option" = "yes" ]
then
@@ -56,7 +69,7 @@ _complete_appsh() {
return 0
fi
- case $prev in
+ case "$prev" in
-n)
values=$(./app instance list -P name)
COMPREPLY=($(compgen -W "$values" -- ${cur}))
@@ -70,6 +83,15 @@ _complete_appsh() {
return 0
fi
;;
+ -r)
+ COMPREPLY="${_appsh_resolvers[@]}"
+ COMPREPLY=($(compgen -W "$COMPREPLY" -- ${cur}))
+ return
+ ;;
+ -u)
+ COMPREPLY=($(compgen -f -- ${cur}))
+ return
+ ;;
esac
if [ -n "$has_n" -a -z "$has_i" ]
@@ -77,13 +99,25 @@ _complete_appsh() {
opts="$opts -i"
fi
- if [ -z "$has_method" ]
- then
- opts="$opts ${_appsh_methods[@]}"
- fi
+ has_method_group=$has_method_group
+ has_method=$has_method
+ case "$has_method_group" in
+ instance)
+ if [ -z $has_method ]
+ then
+ opts="$opts install list list-versions set-current"
+ else
+ case "$has_method" in
+ install)
+ opts="$opts -r -u"
+ ;;
+ esac
+ fi
+ ;;
+ esac
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
set +x
}
-complete -F _complete_appsh app
+complete -d -F _complete_appsh app
diff --git a/docs/README.md b/docs/README.md
index 22a8522..c3cb679 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1,14 +1,14 @@
Installation
------------
-NOTE: No implemented yet
-
- git clone http:/.../app.sh.git
+ git clone http://.../app.sh.git
mkdir /opt/apps
cd /opt/apps
ln -s .../app.sh.git/app.sh app.sh
+NOTE: The bash completion is not perfect yet.
+
echo 'source .../app.sh.git/app_completion' >> ~/.bashrc
Or was it `~/.bash_profile`? hmm
@@ -103,3 +103,22 @@ Unclassified:
* `APPSH_HOME`
* `BASEDIR`
+Directory Hierarchy
+-------------------
+
+### Current
+
+App.sh related:
+
+ ./app
+ ./.app/lib bash libraries used by app.sh and methods
+ ./.app/var runtime data
+
+Applications:
+
+ ./<name>/<instance>/
+ current - symlink to the currently installed app
+ versions/ - collection with all installed versions
+ 1.0/
+ 1.1/
+ 2.0/
diff --git a/test/data/app-a/root/bin/app-a b/test/data/app-a/root/bin/app-a
index e69de29..7d251a0 100644
--- a/test/data/app-a/root/bin/app-a
+++ b/test/data/app-a/root/bin/app-a
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+me=`basename $0`
+
+for i in {1..10}
+do
+ echo "#$i: `date`" >> $me.log
+ sleep 1
+done
diff --git a/test/data/app-a/root/etc/app.conf b/test/data/app-a/root/etc/app.conf
new file mode 100644
index 0000000..d2c3f48
--- /dev/null
+++ b/test/data/app-a/root/etc/app.conf
@@ -0,0 +1 @@
+app.bin=bin/app-a
diff --git a/test/it-install-remove.bats b/test/it-install-remove.bats
new file mode 100755
index 0000000..98a79c9
--- /dev/null
+++ b/test/it-install-remove.bats
@@ -0,0 +1,25 @@
+#!/usr/bin/env bats
+# vim: set filetype=sh:
+
+load utils
+
+@test "install remove roundtrip" {
+ mkzip "app-a"
+ a="-n app-a -i prod"
+ app instance install \
+ -r file \
+ -u $BATS_TEST_DIRNAME/data/app-a.zip \
+ $a
+
+ [ ! -r .app/var/pid/$name-$instance.pid ]
+ app $a operate start; echo_lines
+ [ -r .app/var/pid/$name-$instance.pid ]
+
+ app $a operate stop; echo_lines
+ [ ! -r .app/var/pid/$name-$instance.pid ]
+
+# app instance install \
+# -r file \
+# -u $HOME/.m2/repository/io/trygvis/appsh/examples/jenkins/1.0-SNAPSHOT/jenkins-1.0-SNAPSHOT.zip \
+# -n jenkins -i env-a
+}
diff --git a/test/utils.bash b/test/utils.bash
index 0edead8..03871f8 100644
--- a/test/utils.bash
+++ b/test/utils.bash
@@ -30,5 +30,6 @@ mkzip() {
}
app() {
- run ./app "$@"
+ (set -x
+ run ./app "$@")
}