From 2c7a659b8a8d0d7a082aed01ab44e5710841412b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 14 Oct 2012 11:26:54 +0200 Subject: o Adjusting app-conf and app-operate after refactoring. --- .app/lib/app-conf | 12 +++------ .app/lib/app-operate | 72 ++++++++++++++++++---------------------------------- 2 files changed, 27 insertions(+), 57 deletions(-) diff --git a/.app/lib/app-conf b/.app/lib/app-conf index fa705e4..29b74dd 100644 --- a/.app/lib/app-conf +++ b/.app/lib/app-conf @@ -111,19 +111,13 @@ method_conf_usage() { } method_conf() { - local name - local instance + local name="$1"; shift + local instance="$1"; shift local mode="list" - while getopts "n:i:s:d:" opt + while getopts "s:d:" opt do case $opt in - n) - name="$OPTARG" - ;; - i) - instance="$OPTARG" - ;; d) mode="delete" key="$OPTARG" diff --git a/.app/lib/app-operate b/.app/lib/app-operate index fc0d63f..d2f3a00 100644 --- a/.app/lib/app-operate +++ b/.app/lib/app-operate @@ -1,58 +1,24 @@ #!/bin/bash -start_usage() { +operate_usage() { if [ -n "$1" ] then echo "Error:" "$@" >&2 fi - echo "usage: $0 start -n name -i instance" >&2 - exit 1 -} - -stop_usage() { - if [ -n "$1" ] - then - echo "Error:" "$@" >&2 - fi - - echo "usage: $0 stop -n name -i instance" >&2 + echo "usage: $0 [operate method] -n name -i instance" >&2 exit 1 } # TODO: set ulimit # TODO: set umask # TODO: change group newgrp/sg -method_start() { - run_control start_usage "start" "$@" -} - -method_stop() { - run_control stop_usage "stop" "$@" -} - run_control() { - local usage=$0; shift local method=$1; shift - local name - local instance - - while getopts "n:i:" opt - do - case $opt in - n) - name=$OPTARG - ;; - i) - instance=$OPTARG - ;; - \?) - $usage "Invalid option: -$OPTARG" - ;; - esac - done + local name=$1; shift + local instance=$1; shift - assert_is_instance $usage "$name" "$instance" + assert_is_instance operate_usage "$name" "$instance" ( cd $name/$instance/current @@ -91,7 +57,7 @@ run_control() { echo "Application ${method}ed" ;; *) - echo "Error starting $name/$instance" + echo "Error ${method}ing $name/$instance" ;; esac ) @@ -103,9 +69,9 @@ method_operate_usage() { echo "Error:" $@ >&2 fi - echo "usage: $0 operate " >&2 + echo "usage: $0 operate " >&2 echo "" >&2 - echo "Available methods:" >&2 + echo "Available operate methods:" >&2 echo " start" >&2 echo " stop" >&2 echo " restart" >&2 @@ -113,18 +79,28 @@ method_operate_usage() { } method_operate() { + local name="$1"; shift + local instance="$1"; shift + local method="$1" + if [ $# -gt 0 ] then - method=$1 shift fi case "$method" in - start) method_start $first "$@" ;; - stop) method_stop $first "$@" ;; - status) method_status $first "$@" ;; - restart) method_restart $first "$@" ;; - *) method_operate_usage ;; + start) run_control "start" "$name" "$instance" "$@" ;; + stop) run_control "stop" "$name" "$instance" "$@" ;; + status) run_control "status" "$name" "$instance" "$@" ;; + restart) run_control "restart" "$name" "$instance" "$@" ;; + *) + if [ -z "$method" ] + then + method_operate_usage + else + method_operate_usage "Unknown method $method" + fi + ;; esac exit $? } -- cgit v1.2.3