diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2010-11-01 14:17:59 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2010-11-01 14:17:59 -0200 |
commit | 69ba766373b5247cf28eb8aa4308ac679b1b5c71 (patch) | |
tree | 3f44fae3602c2df555309095ada9b41011bb1000 | |
parent | b44f5147ebb4d06b9a2a3a0f85ff5b53a529ac98 (diff) | |
download | hydra-69ba766373b5247cf28eb8aa4308ac679b1b5c71.tar.gz hydra-69ba766373b5247cf28eb8aa4308ac679b1b5c71.tar.bz2 |
Fixing basic command line evaluation
-rwxr-xr-x | hydra | 17 | ||||
-rw-r--r-- | lib/hydra/misc | 35 | ||||
-rwxr-xr-x | share/hydra/register | 15 |
3 files changed, 33 insertions, 34 deletions
@@ -49,19 +49,24 @@ function hydra_load { source $APP_BASE/lib/hydra/functions || exit 1 } -# Command-line parameters +# Basename BASENAME="`basename $0`" -ACTION="$1" + +# Adjust hydra parameter +if [ "$BASENAME" == "hydra" ]; then + export HYDRA="$1" + shift +fi + +# Load +hydra_load $* # Command-line parser if [ -z "$ACTION" ]; then - echo "usage: $BASENAME <command> [arguments]" + echo "usage: $BASENAME [hydra] <command> [arguments]" exit 1 fi -# Load functions -hydra_load $* - # Dispatch if hydra_has_action $ACTION; then hydra_dispatch $* diff --git a/lib/hydra/misc b/lib/hydra/misc index 5691465..88ffec1 100644 --- a/lib/hydra/misc +++ b/lib/hydra/misc @@ -44,28 +44,27 @@ function hydra_config { # Check if there is a given action function hydra_has_action { - if [ -z "$ACTIONS" ]; then - echo "Your have to set ACTIONS variable in the code" - exit 1 - fi + if [ -z "$ACTIONS" ]; then + echo "Your have to set ACTIONS variable in the code" + exit 1 + fi - if [ -e "$ACTIONS/$1" ]; then - true - else - false - fi + if [ -e "$ACTIONS/$1" ]; then + true + else + false + fi } # Execute an action function hydra_exec { # Setup action="$1" - basedir="$2" shift 2 # Dispatch if hydra_has_action $action; then - $ACTIONS/$action $basedir $* + $ACTIONS/$action $* fi } @@ -75,6 +74,8 @@ function hydra_set_env { echo "Error: missing arguments for hydra_set_env" exit 1 fi + + ACTION="$1" } # Get a command argument @@ -100,15 +101,5 @@ function hydra_action_usage { } function hydra_dispatch { - BASEDIR="`hydra_config $KEYRING`" - - # Dispatch - if [ ! -z "$BASEDIR" ]; then - shift 2 - hydra_exec $ACTION $BASEDIR $* - exit $? - else - echo "No keydir configured for $KEYRING" - exit 1 - fi + hydra_exec $ACTION $* } diff --git a/share/hydra/register b/share/hydra/register index bf36540..677a73d 100755 --- a/share/hydra/register +++ b/share/hydra/register @@ -4,17 +4,20 @@ # CONFIG="$HOME/.hydra/config" -HYDRA="$1" -BASEDIR="$2" -PUPPET="$(dirname `find $BASEDIR -name puppet.conf`)" +BASEDIR="$1" -mkdir -p `dirname $CONFIG` - -if grep -q -e "^$HYDRA=" $CONFIG; then +if [ -z "$BASEDIR" ]; then + echo "Usage: hydra [hydra] register <path>" + exit 1 +elif grep -q -e "^$HYDRA=" $CONFIG &> /dev/null; then echo "Hydra $HYDRA already defined" exit 1 fi +# Folder setup +#PUPPET="$(dirname `find $BASEDIR -name puppet.conf`)" +mkdir -p `dirname $CONFIG` + # Reparse basedir to force absolute folder BASEDIR="`cd $BASEDIR && pwd`" |