This repository was archived by the owner on Apr 29, 2021. It is now read-only.
File tree 1 file changed +53
-42
lines changed 1 file changed +53
-42
lines changed Original file line number Diff line number Diff line change @@ -57,53 +57,64 @@ export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
57
57
export BATS_CWD=" $( abs_dirname .) "
58
58
export PATH=" $BATS_LIBEXEC :$PATH "
59
59
60
- options=()
60
+ unset count_flag pretty
61
+ [ -t 0 ] && [ -t 1 ] && pretty=" 1"
62
+ [ -n " $CI " ] && pretty=" "
63
+
61
64
arguments=()
62
- for arg in " $@ " ; do
63
- if [ " ${arg: 0: 1} " = " -" ]; then
64
- if [ " ${arg: 1: 1} " = " -" ]; then
65
- options[${# options[*]} ]=" ${arg: 2} "
66
- else
67
- index=1
68
- while option=" ${arg: $index : 1} " ; do
69
- [ -n " $option " ] || break
70
- options[${# options[*]} ]=" $option "
71
- let index+=1
72
- done
73
- fi
74
- else
65
+
66
+ while [[ $# -gt 0 ]]; do
67
+ arg=" $1 "
68
+
69
+ if [ ! ${arg: 0: 1} = " -" ]; then
75
70
arguments[${# arguments[*]} ]=" $arg "
71
+ shift
72
+ continue
76
73
fi
77
- done
78
74
79
- unset count_flag pretty
80
- [ -t 0 ] && [ -t 1 ] && pretty=" 1"
81
- [ -n " $CI " ] && pretty=" "
75
+ options=()
76
+ pat=" ^-[a-z][a-z]+"
77
+ opt_grouped=" false" # whether a option is in a group or not
78
+ if [[ $arg =~ $pat ]]; then
79
+ index=1
80
+ while opt=" ${arg: $index : 1} " ; do
81
+ [ -n " $opt " ] || break
82
+ options[${# options[*]} ]=" -$opt "
83
+ let index+=1
84
+ done
85
+ opt_grouped=" true"
86
+ else
87
+ options[${# options[*]} ]=$arg
88
+ fi
89
+
90
+ for opt in ${options[@]} ; do
91
+ case $opt in
92
+ " -h" | " --help" )
93
+ help
94
+ exit 0
95
+ ;;
96
+ " -v" | " --version" )
97
+ version
98
+ exit 0
99
+ ;;
100
+ " -c" | " --count" )
101
+ count_flag=" -c"
102
+ ;;
103
+ " -t" | " --tap" )
104
+ pretty=" "
105
+ ;;
106
+ " -p" | " --pretty" )
107
+ pretty=" 1"
108
+ ;;
109
+ * )
110
+ usage >&2
111
+ exit 1
112
+ ;;
113
+ esac
114
+ done
82
115
83
- for option in " ${options[@]} " ; do
84
- case " $option " in
85
- " h" | " help" )
86
- help
87
- exit 0
88
- ;;
89
- " v" | " version" )
90
- version
91
- exit 0
92
- ;;
93
- " c" | " count" )
94
- count_flag=" -c"
95
- ;;
96
- " t" | " tap" )
97
- pretty=" "
98
- ;;
99
- " p" | " pretty" )
100
- pretty=" 1"
101
- ;;
102
- * )
103
- usage >&2
104
- exit 1
105
- ;;
106
- esac
116
+ shift
117
+ continue
107
118
done
108
119
109
120
if [ " ${# arguments[@]} " -eq 0 ]; then
You can’t perform that action at this time.
0 commit comments