TT#142950 scripts: Fix options parsing

Switch all code to use a loop to parse options so that these can parse
multiple options (currently some scripts would simply parse one or
another but not several), and to make them easier to extend.

Change-Id: I5e902f2d7d8db78e66e48db1237924fa7d8fdda1
mr10.3.1
Guillem Jover 4 years ago committed by ngcp-config
parent 2b8dd4c021
commit e875197950

@ -21,13 +21,14 @@ fi
MODIFIED_ONLY=false
check_args=()
if [ -n "${1:-}" ] ; then
while [ -n "${1:-}" ] ; do
case "$1" in
*--modified-only*) MODIFIED_ONLY=true ; shift ;;
*--ignore-branch-check*) check_args+=( --ignore-branch-check ) ; shift ;;
*--ignore-shared-storage-check*) check_args+=( --ignore-shared-storage-check ) ; shift ;;
*) break ;;
esac
fi
done
# Sanity check the YAML and schema files.
# NOTE: we can't blindly pass "$@" to the check script,

@ -31,24 +31,31 @@ help() {
RC=0
b_show_diff=false
if [ "${#:-}" == "2" ]; then
file="$1"
option="$2"
elif [ "${#:-}" == "3" ]; then
if [ "$1" == "--diff" ]; then
b_show_diff=true
else
log_error "unsupported option '$1'. Exiting."
help >&2
exit 1
fi
file="$2"
option="$3"
else
while [ -n "${1:-}" ]; do
case "$1" in
--diff)
b_show_diff=true
shift
;;
--*)
log_error "unsupported option '$1'. Exiting."
help >&2
exit 1
;;
*)
break
;;
esac
done
if [ "${#:-}" != "2" ]; then
help >&2
exit 1
fi
file="$1"
option="$2"
[ -f "${file}" ] || (log_error "missing ${file}. Exiting." ; exit 1)
[ -z "${option}" ] && ( log_error "missing option to set. Exiting." ; exit 1)
log_debug "Deleting option '${option}' from '${file}'"

@ -286,20 +286,30 @@ patch_footer() {
declare -a bad_files=()
declare -a good_files=()
case "${1:-}" in
"--help")
patch_help
;;
"--from-customtt")
shift # removing '--from-customtt'
patch_import "$@"
patch_footer "customtt"
;;
*)
patch_patch "$@"
patch_footer "patchtt"
;;
esac
patch_type=patchtt
while [ -n "${1:-}" ] ; do
case "${1:-}" in
--help)
patch_help
exit 0
;;
--from-customtt)
patch_type=customtt
shift
;;
*)
break
;;
esac
done
if [ "${patch_type}" = 'patchtt' ]; then
patch_patch "$@"
else
patch_import "$@"
fi
patch_footer "${patch_type}"
exit "${RC:-0}"

@ -229,11 +229,22 @@ RUNNING_FILE="${RUN_DIR}/ngcpcfg-services.running"
DRYRUN='false'
FORCE_ALL_SERVICES='false'
if [[ "${1:-}" == "test" ]] || [[ "${1:-}" == "--dry-run" ]]; then
DRYRUN='true'
elif [[ "${1:-}" == "--force-all-services" ]]; then
FORCE_ALL_SERVICES='true'
fi
while [ -n "${1:-}" ]; do
case "$1" in
test|--dry-run)
DRYRUN='true'
shift
;;
--force-all-services)
FORCE_ALL_SERVICES='true'
shift
;;
*)
break
;;
esac
done
log_debug "DRYRUN = ${DRYRUN}"
log_debug "FORCE_ALL_SERVICES = ${FORCE_ALL_SERVICES}"

@ -31,24 +31,31 @@ help() {
RC=0
b_show_diff=false
if [ "${#:-}" == "2" ]; then
file="$1"
data="$2"
elif [ "${#:-}" == "3" ]; then
if [ "$1" == "--diff" ]; then
b_show_diff=true
else
log_error "unsupported option '$1'. Exiting."
help >&2
exit 1
fi
file="$2"
data="$3"
else
while [ -n "${1:-}" ]; do
case "$1" in
--diff)
b_show_diff=true
shift
;;
--*)
log_error "unsupported option '$1'. Exiting."
help >&2
exit 1
;;
*)
break
;;
esac
done
if [ "${#:-}" != "2" ]; then
help >&2
exit 1
fi
file="$1"
data="$2"
[ -f "${file}" ] || (log_error "missing ${file}. Exiting." ; exit 1)
[ -z "${data}" ] && (log_error "missing data to set. Exiting." ; exit 1)

Loading…
Cancel
Save