Skip to content

Commit 1063adc

Browse files
committed
[revert] : Use getopts
1 parent 2c09756 commit 1063adc

File tree

1 file changed

+51
-67
lines changed

1 file changed

+51
-67
lines changed

tools/msg.sh

Lines changed: 51 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ _help() {
2626
echo "Display a message with a colored app name and message type label"
2727
echo
2828
echo " General type:"
29-
echo " info General message"
30-
echo " warn Warning message"
31-
echo " error Error message"
32-
echo " debug Debug message"
29+
echo " info General message"
30+
echo " warn Warning message"
31+
echo " error Error message"
32+
echo " debug Debug message"
3333
echo
3434
echo " General options:"
35-
echo " -a | --appname [name] Specify the app name"
36-
echo " -c | --adjust-chr [character] Specify the character to adjust the label"
37-
echo " -l | --label [label] Specify the label."
38-
echo " -n | --nocolor No output colored output"
39-
echo " -o | --echo-opts [option] Specify echo options"
40-
echo " -r | --label-color [color] Specify the color of label"
41-
echo " -s | --label-space [number] Specifies the label space."
42-
echo " -x | --bash-debug Enables output bash debugging"
43-
echo " -h | --help This help message"
35+
echo " -a [name] Specify the app name"
36+
echo " -c [character] Specify the character to adjust the label"
37+
echo " -l [label] Specify the label."
38+
echo " -n | --nocolor No output colored output"
39+
echo " -o [option] Specify echo options"
40+
echo " -r [color] Specify the color of label"
41+
echo " -s [number] Specifies the label space."
42+
echo " -x | --bash-debug Enables output bash debugging"
43+
echo " -h | --help This help message"
4444
echo
45-
echo " --nolabel Do not output label"
46-
echo " --noappname Do not output app name"
47-
echo " --noadjust Do not adjust the width of the label"
45+
echo " --nolabel Do not output label"
46+
echo " --noappname Do not output app name"
47+
echo " --noadjust Do not adjust the width of the label"
4848
}
4949

5050
# Message functions
@@ -53,41 +53,19 @@ msg_error() {
5353
}
5454

5555

56-
# Parse options
57-
opt_short="a:c:l:no:r:s:xh"
58-
opt_long="nocolor,bash-debug,help,nolabel,noappname,noadjust,appname:,adjust-chr:,label:,echo-opts:,label-color:,label-space:"
59-
OPT="$(getopt -uo ${opt_short} -l ${opt_long} -- "${@}")"
60-
[[ ${?} != 0 ]] && exit 1
61-
62-
eval set -- "${OPT}"
63-
unset OPT opt_short opt_long
64-
65-
while true; do
66-
case "${1}" in
67-
-a | --appname)
68-
appname="${2}"
69-
shift 2
70-
;;
71-
-c | --adjust-chr)
72-
adjust_chr="${2}"
73-
shift 2
74-
;;
75-
-l | --label)
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)
7661
customized_label=true
77-
msg_label="${2}"
78-
shift 2
79-
;;
80-
-n | --nocolor)
81-
nocolor=true
82-
shift 1
62+
msg_label="${OPTARG}"
8363
;;
84-
-o | --echo-opts)
85-
echo_opts="${2}"
86-
shift 2
87-
;;
88-
-r | --label-color)
64+
n) nocolor=true ;;
65+
o) echo_opts="${OPTARG}" ;;
66+
r)
8967
customized_label_color=true
90-
case "${2}" in
68+
case ${OPTARG} in
9169
"black")
9270
labelcolor="30"
9371
;;
@@ -117,35 +95,41 @@ while true; do
11795
exit 1
11896
;;
11997
esac
120-
shift 2
121-
;;
122-
-s | --label-space)
123-
label_space="${2}"
124-
shift 2
12598
;;
126-
-x | --bash-debug)
99+
s) label_space="${OPTARG}" ;;
100+
x)
127101
bash_debug=true
128102
set -xv
129-
shift 1
130103
;;
131-
-h | --help)
104+
h)
132105
_help
133106
shift 1
134107
exit 0
135108
;;
136-
--)
137-
shift 1
138-
break
139-
;;
140-
*)
141-
msg_error "Invalid argument '${1}'"
142-
shift 1
143-
_help
144-
exit 1
145-
;;
146-
esac
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
147129
done
148130

131+
shift $((OPTIND - 1))
132+
149133
# Color echo
150134
#
151135
# Text Color

0 commit comments

Comments
 (0)