aboutsummaryrefslogtreecommitdiff
path: root/lib/hydra/action
blob: 0bd37251bc0efb4650ab242d5165778a2014f39d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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
  
  # 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 {
  shift
  hydra_exec $ACTION $*
}

# Evaluate a parameter from the config file
function hydra_eval_parameter {
  if [ -e "$CONFIG" ] && grep -qe "^$1=" $CONFIG; then
    grep -e "^$1=" $CONFIG | tail -n 1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//'
  fi
}