]> gitweb.fluxo.info Git - hydra.git/commitdiff
Splitting lib functions in smaller files
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 21 Nov 2010 19:19:01 +0000 (17:19 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 21 Nov 2010 19:19:01 +0000 (17:19 -0200)
lib/hydra/action [new file with mode: 0644]
lib/hydra/config [new file with mode: 0644]
lib/hydra/functions
lib/hydra/misc
lib/hydra/usage [new file with mode: 0644]

diff --git a/lib/hydra/action b/lib/hydra/action
new file mode 100644 (file)
index 0000000..b5d76a9
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+# 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 [ -e "$ACTIONS/$1" ]; then
+    true
+  else
+    false
+  fi
+}
+
+# Execute an action
+function hydra_exec {
+  # Setup
+  action="$1"
+  shift 2
+  
+  # Dispatch
+  if hydra_has_action $action; then
+    $ACTIONS/$action $*
+  fi
+}
+
+# Get a command argument
+function hydra_get_command {
+  # Aditional parameters
+  COMMAND="$1"
+  
+  if [ -z "$COMMAND" ]; then
+    hydra_action_usage command
+    exit 1
+  fi
+}
+
+# Action dispatcher
+function hydra_dispatch {
+  hydra_exec $ACTION $*
+}
diff --git a/lib/hydra/config b/lib/hydra/config
new file mode 100644 (file)
index 0000000..f45366b
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+# Setup main configuration and load preferences
+function hydra_config_load {
+  local folder="`dirname $CONFIG`"
+
+  if [ -f "$folder" ]; then
+    echo "Converting legacy configuration scheme..."
+    mv $folder $folder.tmp
+    mkdir -p $folder
+    mv $folder.tmp $CONFIG
+  fi
+
+  if [ ! -e "$CONFIG" ]; then
+    echo "Creating $CONFIG..."
+    mkdir `dirname $CONFIG`
+    touch $CONFIG
+    chmod 600 $CONFIG
+    echo "# Hydra config file." > $CONFIG
+    echo "" >> $CONFIG
+  fi
+
+  hydra_config_load_preferences
+}
+
+# Load config preferences
+function hydra_config_load_preferences {
+  # Load custom preferences
+  if [ ! -z "$PREFERENCES" ] && [ -f "$PREFERENCES" ]; then
+    source $PREFERENCES
+  fi
+  
+  hydra_check_preferences
+}
+
+# Check preferences
+function hydra_check_preferences {
+  if [ ! -z "$PUPPET" ] && [ ! -d "$PUPPET" ]; then
+    echo "Puppet folder not found: $PUPPET."
+    exit 1
+  fi
+
+  if [ -z "$PUPPET_KEYS" ]; then
+    PUPPET_KEYS="$PUPPET/files/keys"
+  fi
+}
+
+# Load a parameter from config
+function hydra_config {
+  if [ -z "$CONFIG" ]; then
+    echo "Your have to set CONFIG variable in the code"
+    exit 1
+  elif [ -e "$CONFIG" ]; then
+    grep -e "^$1=" $CONFIG | tail -n 1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//'
+  else
+    echo "Config file not found: $CONFIG"
+    exit 1
+  fi
+}
index 0324bbb47175b609cd745bdfa3e4207832f89471..b07e523d40b7bf560a94fae3bfb173666939902c 100644 (file)
@@ -6,6 +6,9 @@
 # Source required functions
 source $APP_BASE/lib/hydra/git
 source $APP_BASE/lib/hydra/misc
+source $APP_BASE/lib/hydra/usage
+source $APP_BASE/lib/hydra/action
+source $APP_BASE/lib/hydra/config
 source $APP_BASE/lib/hydra/tmpfile
 
 # Setup environment
index fd90e93cf0486ef5eb39ebc5c66575bdfd01fb22..2fd55180b983296fffbc4ba2f7361481ada6a1fd 100644 (file)
@@ -1,89 +1,5 @@
 #!/bin/bash
 
-# Setup main configuration and load preferences
-function hydra_config_load {
-  local folder="`dirname $CONFIG`"
-
-  if [ -f "$folder" ]; then
-    echo "Converting legacy configuration scheme..."
-    mv $folder $folder.tmp
-    mkdir -p $folder
-    mv $folder.tmp $CONFIG
-  fi
-
-  if [ ! -e "$CONFIG" ]; then
-    echo "Creating $CONFIG..."
-    mkdir `dirname $CONFIG`
-    touch $CONFIG
-    chmod 600 $CONFIG
-    echo "# Hydra config file." > $CONFIG
-    echo "" >> $CONFIG
-  fi
-
-  hydra_config_load_preferences
-}
-
-# Load config preferences
-function hydra_config_load_preferences {
-  # Load custom preferences
-  if [ ! -z "$PREFERENCES" ] && [ -f "$PREFERENCES" ]; then
-    source $PREFERENCES
-  fi
-  
-  hydra_check_preferences
-}
-
-# Check preferences
-function hydra_check_preferences {
-  if [ ! -z "$PUPPET" ] && [ ! -d "$PUPPET" ]; then
-    echo "Puppet folder not found: $PUPPET."
-    exit 1
-  fi
-
-  if [ -z "$PUPPET_KEYS" ]; then
-    PUPPET_KEYS="$PUPPET/files/keys"
-  fi
-}
-
-# Load a parameter from config
-function hydra_config {
-  if [ -z "$CONFIG" ]; then
-    echo "Your have to set CONFIG variable in the code"
-    exit 1
-  elif [ -e "$CONFIG" ]; then
-    grep -e "^$1=" $CONFIG | tail -n 1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//'
-  else
-    echo "Config file not found: $CONFIG"
-    exit 1
-  fi
-}
-
-# 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 [ -e "$ACTIONS/$1" ]; then
-    true
-  else
-    false
-  fi
-}
-
-# Execute an action
-function hydra_exec {
-  # Setup
-  action="$1"
-  shift 2
-  
-  # Dispatch
-  if hydra_has_action $action; then
-    $ACTIONS/$action $*
-  fi
-}
-
 # Set needed environment variables and do basic checks.
 function hydra_set_env {
   export CONFIG="$HOME/.hydra/config"
@@ -94,46 +10,6 @@ function hydra_set_env {
   fi
 }
 
-# Get a command argument
-function hydra_get_command {
-  # Aditional parameters
-  COMMAND="$1"
-  
-  if [ -z "$COMMAND" ]; then
-    hydra_action_usage command
-    exit 1
-  fi
-}
-
-# Run the action usage
-function hydra_action_usage {
-  if [ "`type -t "hydra_usage_$BASENAME"`" == "function" ]; then
-    # Use custom action usage
-    hydra_usage_$BASENAME
-  else
-    # Default usage
-    echo "Usage: $NAME <command> [arguments]"
-  fi
-
-  echo "Available commands:"
-  ls $ACTIONS | sed -e 's/^/\t/'
-}
-
-# Action dispatcher
-function hydra_dispatch {
-  hydra_exec $ACTION $*
-}
-
-# Hydra usage
-function hydra_usage_hydra {
-  echo "Usage: hydra [hydra] <command> [arguments]"
-}
-
-# Hydra ctl usage
-function hydra_usage_hydractl {
-  echo "Usage: hydractl <command> [arguments]"
-}
-
 # Read a parameter from user
 function hydra_user_input {
   local input
diff --git a/lib/hydra/usage b/lib/hydra/usage
new file mode 100644 (file)
index 0000000..32acbb0
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# Run the action usage
+function hydra_action_usage {
+  if [ "`type -t "hydra_usage_$BASENAME"`" == "function" ]; then
+    # Use custom action usage
+    hydra_usage_$BASENAME
+  else
+    # Default usage
+    echo "Usage: $NAME <command> [arguments]"
+  fi
+
+  echo "Available commands:"
+  ls $ACTIONS | sed -e 's/^/\t/'
+}
+
+# Hydra usage
+function hydra_usage_hydra {
+  echo "Usage: hydra [hydra] <command> [arguments]"
+}
+
+# Hydra ctl usage
+function hydra_usage_hydractl {
+  echo "Usage: hydractl <command> [arguments]"
+}