Skip to content

Commit 0c6f584

Browse files
committed
[update] : Use getopt
1 parent 2cea492 commit 0c6f584

File tree

1 file changed

+51
-35
lines changed

1 file changed

+51
-35
lines changed

tools/msg.sh

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,42 @@ msg_error() {
5353
}
5454

5555

56-
while getopts "a:c:l:no:r:s:xh-:" arg; do
57-
case ${arg} in
58-
a) appname="${OPTARG}" ;;
59-
c) adjust_chr="${OPTARG}" ;;
60-
l)
56+
# Parse options
57+
ARGUMENT="${@}"
58+
_opt_short="a:c:l:no:r:s:xh"
59+
_opt_long="nocolor,bash-debug,help,nolabel,noappname,noadjust"
60+
OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT})
61+
[[ ${?} != 0 ]] && exit 1
62+
63+
eval set -- "${OPT}"
64+
unset OPT _opt_short _opt_long
65+
66+
while true; do
67+
case "${1}" in
68+
-a)
69+
appname="${2}"
70+
shift 2
71+
;;
72+
-c)
73+
adjust_chr="${2}"
74+
shift 2
75+
;;
76+
-l)
6177
customized_label=true
62-
msg_label="${OPTARG}"
78+
msg_label="${2}"
79+
shift 2
80+
;;
81+
-n)
82+
nocolor=true
83+
shift 1
6384
;;
64-
n) nocolor=true ;;
65-
o) echo_opts="${OPTARG}" ;;
66-
r)
85+
-o)
86+
echo_opts="${2}"
87+
shift 2
88+
;;
89+
-r)
6790
customized_label_color=true
68-
case ${OPTARG} in
91+
case "${2}" in
6992
"black")
7093
labelcolor="30"
7194
;;
@@ -95,41 +118,34 @@ while getopts "a:c:l:no:r:s:xh-:" arg; do
95118
exit 1
96119
;;
97120
esac
121+
shift 2
122+
;;
123+
-s)
124+
label_space="${2}"
125+
shift 2
98126
;;
99-
s) label_space="${OPTARG}" ;;
100-
x)
127+
-x | --bash-debug)
101128
bash_debug=true
102129
set -xv
130+
shift 1
103131
;;
104-
h)
132+
-h | --help)
105133
_help
106134
shift 1
107135
exit 0
108136
;;
109-
-)
110-
case "${OPTARG}" in
111-
"nocolor") nocolor=true ;;
112-
"bash-debug")
113-
bash_debug=true
114-
set -xv
115-
;;
116-
"help")
117-
_help
118-
exit 0
119-
;;
120-
"nolabel") nolabel=true ;;
121-
"noappname") noappname=true ;;
122-
"noadjust") noadjust=true ;;
123-
*)
124-
_help
125-
exit 1
126-
;;
127-
esac
128-
esac
137+
--)
138+
shift 1
139+
break
140+
;;
141+
*)
142+
shift 1
143+
_help
144+
exit 1
145+
;;
146+
esac
129147
done
130148

131-
shift $((OPTIND - 1))
132-
133149
# Color echo
134150
#
135151
# Text Color

0 commit comments

Comments
 (0)