fix: check for settings file existence or exit
parent
2302bfb5a8
commit
21c9940d4d
|
@ -17,6 +17,7 @@ root_command() {
|
||||||
|
|
||||||
local settings=${args[--settings]}
|
local settings=${args[--settings]}
|
||||||
|
|
||||||
|
if [[ $settings ]]; then
|
||||||
if [[ -f $settings ]]; then
|
if [[ -f $settings ]]; then
|
||||||
echo loading settings file $settings
|
echo loading settings file $settings
|
||||||
module_load yaml
|
module_load yaml
|
||||||
|
@ -24,7 +25,9 @@ root_command() {
|
||||||
echo $s_source
|
echo $s_source
|
||||||
echo $s_target
|
echo $s_target
|
||||||
echo $s_host
|
echo $s_host
|
||||||
|
else
|
||||||
|
echo settings file $settings does not exist && return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $s_server_host ]]; then
|
if [[ $s_server_host ]]; then
|
||||||
|
@ -308,6 +311,30 @@ dbackup_usage() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# :command.normalize_input
|
||||||
|
normalize_input() {
|
||||||
|
local arg flags
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
arg="$1"
|
||||||
|
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
|
||||||
|
input+=("${BASH_REMATCH[1]}")
|
||||||
|
input+=("${BASH_REMATCH[2]}")
|
||||||
|
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
|
||||||
|
input+=("${BASH_REMATCH[1]}")
|
||||||
|
input+=("${BASH_REMATCH[2]}")
|
||||||
|
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
|
||||||
|
flags="${BASH_REMATCH[1]}"
|
||||||
|
for (( i=0 ; i < ${#flags} ; i++ )); do
|
||||||
|
input+=("-${flags:i:1}")
|
||||||
|
done
|
||||||
|
else
|
||||||
|
input+=("$arg")
|
||||||
|
fi
|
||||||
|
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
}
|
||||||
# :command.inspect_args
|
# :command.inspect_args
|
||||||
inspect_args() {
|
inspect_args() {
|
||||||
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
|
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
|
||||||
|
@ -342,7 +369,7 @@ parse_requirements() {
|
||||||
--help | -h )
|
--help | -h )
|
||||||
long_usage=yes
|
long_usage=yes
|
||||||
dbackup_usage
|
dbackup_usage
|
||||||
exit 1
|
exit
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
@ -528,6 +555,7 @@ parse_requirements() {
|
||||||
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
# :command.catch_all_filter
|
||||||
# :command.default_assignments
|
# :command.default_assignments
|
||||||
# :command.whitelist_filter
|
# :command.whitelist_filter
|
||||||
}
|
}
|
||||||
|
@ -538,6 +566,11 @@ initialize() {
|
||||||
long_usage=''
|
long_usage=''
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
|
||||||
|
printf "bash version 4 or higher is required\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# :src/initialize.sh
|
# :src/initialize.sh
|
||||||
# Code here runs inside the initialize() function
|
# Code here runs inside the initialize() function
|
||||||
# Use it for anything that you need to run before any other function, like
|
# Use it for anything that you need to run before any other function, like
|
||||||
|
@ -552,7 +585,9 @@ initialize() {
|
||||||
run() {
|
run() {
|
||||||
declare -A args
|
declare -A args
|
||||||
declare -a other_args
|
declare -a other_args
|
||||||
parse_requirements "$@"
|
declare -a input
|
||||||
|
normalize_input "$@"
|
||||||
|
parse_requirements "${input[@]}"
|
||||||
|
|
||||||
if [[ $action == "root" ]]; then
|
if [[ $action == "root" ]]; then
|
||||||
root_command
|
root_command
|
||||||
|
|
|
@ -10,6 +10,7 @@ module_load path
|
||||||
|
|
||||||
local settings=${args[--settings]}
|
local settings=${args[--settings]}
|
||||||
|
|
||||||
|
if [[ $settings ]]; then
|
||||||
if [[ -f $settings ]]; then
|
if [[ -f $settings ]]; then
|
||||||
echo loading settings file $settings
|
echo loading settings file $settings
|
||||||
module_load yaml
|
module_load yaml
|
||||||
|
@ -17,7 +18,9 @@ if [[ -f $settings ]]; then
|
||||||
echo $s_source
|
echo $s_source
|
||||||
echo $s_target
|
echo $s_target
|
||||||
echo $s_host
|
echo $s_host
|
||||||
|
else
|
||||||
|
echo settings file $settings does not exist && return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $s_server_host ]]; then
|
if [[ $s_server_host ]]; then
|
||||||
|
|
Reference in New Issue