From 1dbae2d11a94a1369601663fb25b6486ab4c61e4 Mon Sep 17 00:00:00 2001 From: hayao Date: Sat, 3 Oct 2020 22:44:32 +0900 Subject: [PATCH] [fix] : Changed to getopts for correct interpretation --- tools/msg.sh | 58 ++++++++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/tools/msg.sh b/tools/msg.sh index 2c079b64..7596b8b6 100755 --- a/tools/msg.sh +++ b/tools/msg.sh @@ -25,54 +25,44 @@ _help() { echo " debug Debug message" echo echo " General options:" - echo " -a | --appname [name] Specify the app name" + echo " -a Specify the app name" echo " -n | --nocolor No output colored output" - echo " -o | --echo-opts [opts] Specify echo options" + echo " -o Specify echo options" echo " -x | --bash-debug Enables output bash debugging" echo " -h | --help This help message" } -# Parse options -ARGUMENT="${@}" -_opt_short="a:no:xh" -_opt_long="appname:,nocolor,echo-opts:,bash-debug,help" -OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT}) -[[ ${?} != 0 ]] && exit 1 -eval set -- "${OPT}" -unset OPT _opt_short _opt_long - -while true; do - case ${1} in - -a | --appname) - appname="${2}" - shift 2 - ;; - -n | --nocolor) - nocolor=true - shift 1 - ;; - -o | --echo-opts) - echo_opts="${2}" - shift 2 - ;; - -x | --bash-debug) +while getopts "a:no:xh-:" arg; do + case ${arg} in + a) appname="${OPTARG}" ;; + n) nocolor=true ;; + o) echo_opts="${OPTARG}" ;; + x) bash_debug=true set -xv - shift 1 ;; - -h | --help) + h) _help exit 0 ;; - --) - shift 1 - break - ;; - - esac + -) + case "${OPTARG}" in + "nocolor") nocolor=true ;; + "bash-debug") + bash_debug=true + set -xv + ;; + "help") + _help + exit 0 + ;; + esac + esac done +shift $((OPTIND - 1)) + # Color echo # # Text Color -- 2.11.0