Skip to content

Commit f12c7bb

Browse files
committed
[update] : reSupported long option
1 parent 55661aa commit f12c7bb

File tree

1 file changed

+76
-45
lines changed

1 file changed

+76
-45
lines changed

tools/msg.sh

Lines changed: 76 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,65 +25,96 @@ _help() {
2525
echo "Display a message with a colored app name and message type label"
2626
echo
2727
echo " General type:"
28-
echo " info General message"
29-
echo " warn Warning message"
30-
echo " error Error message"
31-
echo " debug Debug message"
28+
echo " info General message"
29+
echo " warn Warning message"
30+
echo " error Error message"
31+
echo " debug Debug message"
3232
echo
3333
echo " General options:"
34-
echo " -a [name] Specify the app name"
35-
echo " -c [character] Specify the character to adjust the label"
36-
echo " -l [label] Specify the label."
37-
echo " -n | --nocolor No output colored output"
38-
echo " -o [option] Specify echo options"
39-
echo " -s [number] Specifies the label space."
40-
echo " -x | --bash-debug Enables output bash debugging"
41-
echo " -h | --help This help message"
34+
echo " -a | --appname [name] Specify the app name"
35+
echo " -c | --chr [character] Specify the character to adjust the label"
36+
echo " -l | --label [label] Specify the label"
37+
echo " -n | --nocolor No output colored output"
38+
echo " -o | --option [option] Specify echo options"
39+
echo " -s | --space [number] Specifies the label space"
40+
echo " -x | --bash-debug Enables output bash debugging"
41+
echo " -h | --help This help message"
4242
echo
43-
echo " --nolabel Do not output label"
44-
echo " --noappname Do not output app name"
45-
echo " --noadjust Do not adjust the width of the label"
43+
#echo " --labelcolor Specify the color of label"
44+
echo " --nolabel Do not output label"
45+
echo " --noappname Do not output app name"
46+
echo " --noadjust Do not adjust the width of the label"
4647
}
4748

4849

49-
while getopts "a:c:l:no:s:xh-:" arg; do
50-
case ${arg} in
51-
a) appname="${OPTARG}" ;;
52-
c) adjust_chr="${OPTARG}" ;;
53-
l)
50+
# Parse options
51+
ARGUMENT="${@}"
52+
_opt_short="a:c:l:no:s:xh-:"
53+
_opt_long="appname:,chr:,label:,nocolor,option:,space:,bash-debug,help,nolabel,noappname,noadjust"
54+
OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT})
55+
[[ ${?} != 0 ]] && exit 1
56+
57+
eval set -- "${OPT}"
58+
unset OPT _opt_short _opt_long
59+
60+
while true; do
61+
case ${1} in
62+
-a | --appname)
63+
appname="${2}"
64+
shift 2
65+
;;
66+
-c | --chr)
67+
adjust_chr="${2}"
68+
shift 2
69+
;;
70+
-l | --label)
5471
customized_label=true
55-
msg_label="${OPTARG}"
72+
msg_label="${2}"
73+
shift 2
74+
;;
75+
-n | --nocolor)
76+
nocolor=true
77+
shift 1
78+
;;
79+
-o | --option)
80+
echo_opts="${2}"
81+
shift 2
82+
;;
83+
-s | --spade)
84+
label_space="${2}"
85+
shift 2
5686
;;
57-
n) nocolor=true ;;
58-
o) echo_opts="${OPTARG}" ;;
59-
s) label_space="${OPTARG}" ;;
60-
x)
87+
-x | --bash-debug)
6188
bash_debug=true
89+
shift 1
6290
set -xv
6391
;;
64-
h)
92+
-h | --help)
6593
_help
94+
shit 1
6695
exit 0
6796
;;
68-
-)
69-
case "${OPTARG}" in
70-
"nocolor") nocolor=true ;;
71-
"bash-debug")
72-
bash_debug=true
73-
set -xv
74-
;;
75-
"help")
76-
_help
77-
exit 0
78-
;;
79-
"nolabel") nolabel=true ;;
80-
"noappname") noappname=true ;;
81-
"noadjust") noadjust=true ;;
82-
*)
83-
_help
84-
exit 1
85-
;;
86-
esac
97+
--nolabel)
98+
nolabel=true
99+
shift 1
100+
;;
101+
--noappname)
102+
noappname=true
103+
shift 1
104+
;;
105+
--noadjust)
106+
noadjust=true
107+
shift 1
108+
;;
109+
--)
110+
shift
111+
break
112+
;;
113+
*)
114+
_help
115+
shift 1
116+
exit 1
117+
;;
87118
esac
88119
done
89120

0 commit comments

Comments
 (0)