Skip to content

Commit

Permalink
Fixed issues found by shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
svrnm committed Oct 11, 2017
1 parent e702afa commit a40d732
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
41 changes: 20 additions & 21 deletions adc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SCRIPTNAME=$0
# register namespace_command help
function register {
GLOBAL_COMMANDS="$GLOBAL_COMMANDS $1"
GLOBAL_HELP="$GLOBAL_HELP\n$@"
GLOBAL_HELP="$GLOBAL_HELP\n$*"
}
COLOR_WARNING="\033[0;33m"
COLOR_INFO="\033[0;32m"
Expand All @@ -25,27 +25,27 @@ COLOR_DEBUG="\033[0;35m"
COLOR_RESET="\033[0m"
function debug {
if [ "${CONFIG_OUTPUT_VERBOSITY/debug}" != "$CONFIG_OUTPUT_VERBOSITY" ]; then
echo -e "${COLOR_DEBUG}DEBUG: $@${COLOR_RESET}"
echo -e "${COLOR_DEBUG}DEBUG: $*${COLOR_RESET}"
fi
}
function error {
if [ "${CONFIG_OUTPUT_VERBOSITY/error}" != "$CONFIG_OUTPUT_VERBOSITY" ]; then
echo -e "${COLOR_ERROR}ERROR: $@${COLOR_RESET}"
echo -e "${COLOR_ERROR}ERROR: $*${COLOR_RESET}"
fi
}
function warning {
if [ "${CONFIG_OUTPUT_VERBOSITY/warning}" != "$CONFIG_OUTPUT_VERBOSITY" ]; then
echo -e "${COLOR_WARNING}WARNING: $@${COLOR_RESET}"
echo -e "${COLOR_WARNING}WARNING: $*${COLOR_RESET}"
fi
}
function info {
if [ "${CONFIG_OUTPUT_VERBOSITY/info}" != "$CONFIG_OUTPUT_VERBOSITY" ]; then
echo -e "${COLOR_INFO}INFO: $@${COLOR_RESET}"
echo -e "${COLOR_INFO}INFO: $*${COLOR_RESET}"
fi
}
function output {
if [ "${CONFIG_OUTPUT_VERBOSITY}" != "" ]; then
echo -e "$@"
echo -e "$*"
fi
}
function httpClient {
Expand Down Expand Up @@ -113,7 +113,8 @@ function _help {
COMMAND_RESULT="Usage: $SCRIPTNAME <namespace> <command>\n"
COMMAND_RESULT="${COMMAND_RESULT}\nTo execute a action, provide a namespace and a command, e.g. \"dbmon list\" to list all database collectors.\nFinally the following commands in the global namespace can be called directly:\n"
local NAMESPACE=""
local SORTED=`echo -en "$GLOBAL_HELP" | sort`
local SORTED
SORTED=`echo -en "$GLOBAL_HELP" | sort`
OLD_IFS=$IFS
IFS=$'\n'
for LINE in $SORTED; do
Expand All @@ -128,7 +129,7 @@ function _help {
done
IFS=$OLD_IFS
}
register _help Display the global usage information
register _help Display the global usage information
CONTROLLER_LOGIN_STATUS=0
function controller_login {
debug "Login at $CONFIG_CONTROLLER_HOST with $CONFIG_CONTROLLER_CREDENTIALS"
Expand Down Expand Up @@ -159,11 +160,9 @@ function controller_call {
;;
esac
done

shiftOptInd
shift $SHIFTS
ENDPOINT=$@

ENDPOINT=$*
controller_login
# Debug the COMMAND_RESULT from controller_login
debug $COMMAND_RESULT
Expand All @@ -179,7 +178,7 @@ function controller_call {
COMMAND_RESULT="Controller Login Error! Please check hostname and credentials"
fi
}
register controller_call Send a custom HTTP call to a controller
register controller_call Send a custom HTTP call to a controller
function dbmon_create {
echo "Stub"
}
Expand All @@ -202,20 +201,20 @@ function timerange_create {
DURATION_IN_MINUTES=${OPTARG}
TYPE="BEFORE_NOW"
;;
esac
esac
done;
shiftOptInd
shift $SHIFTS
TIMERANGE_NAME=$@
TIMERANGE_NAME=$*
controller_call -X POST -d "{\"name\":\"$TIMERANGE_NAME\",\"timeRange\":{\"type\":\"$TYPE\",\"durationInMinutes\":$DURATION_IN_MINUTES,\"startTime\":$START_TIME,\"endTime\":$END_TIME}}" /controller/restui/user/createCustomRange
}
register timerange_create Create a custom time range
register timerange_create Create a custom time range
function timerange_list {
controller_call -X GET /controller/restui/user/getAllCustomTimeRanges
}
register timerange_list List all custom timeranges available on the controller
function timerange_delete {
local TIMERANGE_ID=$@
local TIMERANGE_ID=$*
if [[ $TIMERANGE_ID =~ ^[0-9]+$ ]]; then
controller_call -X POST -d "$TIMERANGE_ID" /controller/restui/user/deleteCustomRange
else
Expand Down Expand Up @@ -279,7 +278,7 @@ do
D)
CONFIG_OUTPUT_VERBOSITY=${OPTARG}
debug "Set CONFIG_OUTPUT_VERBOSITY=${CONFIG_OUTPUT_VERBOSITY}"
esac
esac
done
shiftOptInd
shift $SHIFTS
Expand All @@ -295,17 +294,17 @@ if [ "${GLOBAL_COMMANDS/${NAMESPACE}_}" != "$GLOBAL_COMMANDS" ] ; then
COMMAND=$2
if [ "$COMMAND" == "" ] ; then
_help
fi
fi
if [ "${GLOBAL_COMMANDS/${NAMESPACE}_${COMMAND}}" != "$GLOBAL_COMMANDS" ] ; then
debug "${NAMESPACE}_${COMMAND} is a valid command"
shift 2
${NAMESPACE}_${COMMAND} $@
${NAMESPACE}_${COMMAND} "$@"
fi
# Check if this is a global command
elif [ "${GLOBAL_COMMANDS/_${NAMESPACE}}" != "$GLOBAL_COMMANDS" ] ; then
debug "_${NAMESPACE} found as global command"
shift 1
_${NAMESPACE} $@
shift 1
_${NAMESPACE} "$@"
fi
if [ "$COMMAND_RESULT" != "" ]; then
output $COMMAND_RESULT
Expand Down
8 changes: 4 additions & 4 deletions commands/controller/call.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ function controller_call {
;;
esac
done

shiftOptInd
shift $SHIFTS

ENDPOINT=$@
ENDPOINT=$*

controller_login
# Debug the COMMAND_RESULT from controller_login
debug $COMMAND_RESULT
Expand All @@ -36,4 +36,4 @@ function controller_call {
fi
}

register controller_call Send a custom HTTP call to a controller
register controller_call Send a custom HTTP call to a controller
5 changes: 3 additions & 2 deletions commands/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ function _help {
COMMAND_RESULT="Usage: $SCRIPTNAME <namespace> <command>\n"
COMMAND_RESULT="${COMMAND_RESULT}\nTo execute a action, provide a namespace and a command, e.g. \"dbmon list\" to list all database collectors.\nFinally the following commands in the global namespace can be called directly:\n"
local NAMESPACE=""
local SORTED=`echo -en "$GLOBAL_HELP" | sort`
local SORTED
SORTED=`echo -en "$GLOBAL_HELP" | sort`
OLD_IFS=$IFS
IFS=$'\n'
for LINE in $SORTED; do
Expand All @@ -20,4 +21,4 @@ function _help {
IFS=$OLD_IFS
}

register _help Display the global usage information
register _help Display the global usage information
6 changes: 3 additions & 3 deletions commands/timerange/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ function timerange_create {
DURATION_IN_MINUTES=${OPTARG}
TYPE="BEFORE_NOW"
;;
esac
esac
done;
shiftOptInd
shift $SHIFTS
TIMERANGE_NAME=$@
TIMERANGE_NAME=$*
controller_call -X POST -d "{\"name\":\"$TIMERANGE_NAME\",\"timeRange\":{\"type\":\"$TYPE\",\"durationInMinutes\":$DURATION_IN_MINUTES,\"startTime\":$START_TIME,\"endTime\":$END_TIME}}" /controller/restui/user/createCustomRange
}

register timerange_create Create a custom time range
register timerange_create Create a custom time range
2 changes: 1 addition & 1 deletion commands/timerange/delete.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

function timerange_delete {
local TIMERANGE_ID=$@
local TIMERANGE_ID=$*
if [[ $TIMERANGE_ID =~ ^[0-9]+$ ]]; then
controller_call -X POST -d "$TIMERANGE_ID" /controller/restui/user/deleteCustomRange
else
Expand Down
10 changes: 5 additions & 5 deletions helpers/output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ COLOR_RESET="\033[0m"

function debug {
if [ "${CONFIG_OUTPUT_VERBOSITY/debug}" != "$CONFIG_OUTPUT_VERBOSITY" ]; then
echo -e "${COLOR_DEBUG}DEBUG: $@${COLOR_RESET}"
echo -e "${COLOR_DEBUG}DEBUG: $*${COLOR_RESET}"
fi
}

function error {
if [ "${CONFIG_OUTPUT_VERBOSITY/error}" != "$CONFIG_OUTPUT_VERBOSITY" ]; then
echo -e "${COLOR_ERROR}ERROR: $@${COLOR_RESET}"
echo -e "${COLOR_ERROR}ERROR: $*${COLOR_RESET}"
fi
}

function warning {
if [ "${CONFIG_OUTPUT_VERBOSITY/warning}" != "$CONFIG_OUTPUT_VERBOSITY" ]; then
echo -e "${COLOR_WARNING}WARNING: $@${COLOR_RESET}"
echo -e "${COLOR_WARNING}WARNING: $*${COLOR_RESET}"
fi
}

function info {
if [ "${CONFIG_OUTPUT_VERBOSITY/info}" != "$CONFIG_OUTPUT_VERBOSITY" ]; then
echo -e "${COLOR_INFO}INFO: $@${COLOR_RESET}"
echo -e "${COLOR_INFO}INFO: $*${COLOR_RESET}"
fi
}

function output {
if [ "${CONFIG_OUTPUT_VERBOSITY}" != "" ]; then
echo -e "$@"
echo -e "$*"
fi
}
12 changes: 6 additions & 6 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SCRIPTNAME=$0
# register namespace_command help
function register {
GLOBAL_COMMANDS="$GLOBAL_COMMANDS $1"
GLOBAL_HELP="$GLOBAL_HELP\n$@"
GLOBAL_HELP="$GLOBAL_HELP\n$*"
}

source ./helpers/output.sh
Expand Down Expand Up @@ -81,7 +81,7 @@ do
D)
CONFIG_OUTPUT_VERBOSITY=${OPTARG}
debug "Set CONFIG_OUTPUT_VERBOSITY=${CONFIG_OUTPUT_VERBOSITY}"
esac
esac
done

shiftOptInd
Expand All @@ -102,17 +102,17 @@ if [ "${GLOBAL_COMMANDS/${NAMESPACE}_}" != "$GLOBAL_COMMANDS" ] ; then
COMMAND=$2
if [ "$COMMAND" == "" ] ; then
_help
fi
fi
if [ "${GLOBAL_COMMANDS/${NAMESPACE}_${COMMAND}}" != "$GLOBAL_COMMANDS" ] ; then
debug "${NAMESPACE}_${COMMAND} is a valid command"
shift 2
${NAMESPACE}_${COMMAND} $@
${NAMESPACE}_${COMMAND} "$@"
fi
# Check if this is a global command
elif [ "${GLOBAL_COMMANDS/_${NAMESPACE}}" != "$GLOBAL_COMMANDS" ] ; then
debug "_${NAMESPACE} found as global command"
shift 1
_${NAMESPACE} $@
shift 1
_${NAMESPACE} "$@"
fi

if [ "$COMMAND_RESULT" != "" ]; then
Expand Down

0 comments on commit a40d732

Please sign in to comment.