You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Learn more about it [on GitHub](https://github.com/hyperupcall/bake)
17
17
18
18
if [ "$0"!="${BASH_SOURCE[0]}" ] && [ "$BAKE_INTERNAL_CAN_SOURCE"!='yes' ];then
19
-
printf'%s\n''Error: This file should not be sourced'>&2
19
+
printf'%s\n'"Error: This file should not be sourced">&2
20
20
return 1
21
21
fi
22
22
@@ -91,59 +91,25 @@ bake.assert_cmd() {
91
91
fi
92
92
}
93
93
94
-
# @description Determine if a flag was passed as an argument
95
-
# @arg $1 string Flag name to test for
96
-
# @arg $@ string Rest of the arguments to search through
97
-
bake.has_flag() {
98
-
local flag_name="$1"
99
-
100
-
if [ -z"$flag_name" ];then
101
-
bake.die "Argument must not be empty"
102
-
fi
103
-
if!shift;then
104
-
bake.die 'Failed to shift'
105
-
fi
106
-
107
-
local arg=
108
-
for arg;do
109
-
if [ "$arg"="$flag_name" ];then
110
-
return 0
111
-
fi
112
-
done;unset -v arg
113
-
114
-
return 1
115
-
}
116
-
117
-
# @description Change the behavior of Bake. See [guide.md](./docs/guide.md) for details
94
+
# @description Change the behavior of Bake
118
95
# @arg $1 string Name of config property to change
119
96
# @arg $2 string New value of config property
120
97
bake.cfg() {
121
-
local cfg="$1"
122
-
local value="$2"
98
+
local cfg=$1
99
+
local value=$2
123
100
124
101
case$cfgin
125
102
stacktrace)
126
103
case$valuein
127
-
yes) __bake_internal_warn "Passing either 'yes' or 'no' as a value for 'bake.cfg stacktrace' is deprecated. Instead, use either 'on' or 'off'"; __bake_cfg_stacktrace='on' ;;
128
-
no) __bake_internal_warn "Passing either 'yes' or 'no' as a value for 'bake.cfg stacktrace' is deprecated. Instead, use either 'on' or 'off'"; __bake_cfg_stacktrace='off' ;;
129
-
on|off) __bake_cfg_stacktrace=$value ;;
130
-
*) __bake_internal_die2 "Config property '$cfg' accepts only either 'on' or 'off'" ;;
104
+
yes|no) __bake_cfg_stacktrace=$value ;;
105
+
*) __bake_internal_die2 "Config property '$cfg' accepts only either 'yes' or 'no'" ;;
131
106
esac
132
107
;;
133
108
pedantic-task-cd)
134
109
case$valuein
135
-
yes) __bake_internal_warn "Passing either 'yes' or 'no' as a value for 'bake.cfg pedantic-task-cd' is deprecated. Instead, use either 'on' or 'off'";trap'__bake_trap_debug''DEBUG' ;;
136
-
no) __bake_internal_warn "Passing either 'yes' or 'no' as a value for 'bake.cfg pedantic-task-cd' is deprecated. Instead, use either 'on' or 'off'";trap - 'DEBUG' ;;
137
-
on) trap'__bake_trap_debug''DEBUG' ;;
138
-
off) trap - 'DEBUG' ;;
139
-
*) __bake_internal_die2 "Config property '$cfg' accepts only either 'on' or 'off'" ;;
140
-
esac
141
-
;;
142
-
big-print)
143
-
case$valuein
144
-
yes|no) __bake_internal_warn "Passing either 'yes' or 'no' as a value for 'bake.cfg big-print' is deprecated. Instead, use either 'on' or 'off'" ;;
145
-
on|off) ;;
146
-
*) __bake_internal_die2 "Config property '$cfg' accepts only either 'on' or 'off'" ;;
110
+
yes) trap'__bake_trap_debug''DEBUG' ;;
111
+
no) trap - 'DEBUG' ;;
112
+
*) __bake_internal_die2 "Config property '$cfg' accepts only either 'yes' or 'no'" ;;
147
113
esac
148
114
;;
149
115
*)
@@ -155,7 +121,7 @@ bake.cfg() {
155
121
# @description Prints stacktrace
156
122
# @internal
157
123
__bake_print_stacktrace() {
158
-
if [ "$__bake_cfg_stacktrace"='on' ];then
124
+
if [ "$__bake_cfg_stacktrace"='yes' ];then
159
125
if __bake_is_color;then
160
126
printf'\033[4m%s\033[0m\n''Stacktrace:'
161
127
else
@@ -201,17 +167,11 @@ __bake_trap_debug() {
201
167
# @exitcode 1 if should not print color
202
168
# @internal
203
169
__bake_is_color() {
204
-
local fd="1"
205
-
206
-
if [[ ${NO_COLOR+x}||"$TERM"='dumb' ]];then
170
+
if [[ -v NO_COLOR ||$TERM== dumb ]];then
207
171
return 1
208
-
fi
209
-
210
-
if [ -t"$fd" ];then
172
+
else
211
173
return 0
212
174
fi
213
-
214
-
return 1
215
175
}
216
176
217
177
# @description Calls `__bake_internal_error` and terminates with code 1
@@ -270,38 +230,15 @@ __bake_error() {
270
230
# @description Nicely prints all 'Bakefile.sh' tasks to standard output
271
231
# @internal
272
232
__bake_print_tasks() {
273
-
printf'%s\n''Tasks:'
274
-
local str=
275
-
276
233
# shellcheck disable=SC1007,SC2034
277
-
local regex="^([[:space:]]*function[[:space:]]*)?task\.(.*?)\(\)[[:space:]]*\{[[:space:]]*(#[[:space:]]*(.*))?"
234
+
local regex="^(([[:space:]]*function[[:space:]]*)?task\.(.*?)\(\)).*"
278
235
local line=
236
+
printf'%s\n''Tasks:'
279
237
while IFS= read -r line || [ -n"$line" ];do
280
238
if [[ "$line"=~$regex ]];then
281
-
str+=" -> ${BASH_REMATCH[2]}"
282
-
283
-
local task_comment=${BASH_REMATCH[4]}
284
-
if [ -n"$task_comment" ];then
285
-
if __bake_is_color;then
286
-
str+=$'\033[3m'"($task_comment)"$'\033[0m'
287
-
else
288
-
str+=" ($task_comment)"
289
-
fi
290
-
fi
291
-
292
-
str+=$'\n'
239
+
printf'%s\n'" -> ${BASH_REMATCH[3]}"
293
240
fi
294
241
done<"$BAKE_FILE";unset -v line
295
-
296
-
if [ -z"$str" ];then
297
-
if __bake_is_color;then
298
-
str=$'\033[3mNo tasks\033[0m\n'
299
-
else
300
-
str=$' No tasks\n'
301
-
fi
302
-
fi
303
-
304
-
printf'%s'"$str"
305
242
} >&2
306
243
307
244
# @description Prints text that takes up the whole terminal width
@@ -310,21 +247,13 @@ __bake_print_tasks() {
310
247
__bake_print_big() {
311
248
local print_text="$1"
312
249
313
-
if [ "$__bake_cfg_big_print"='off' ];then
314
-
return
315
-
fi
316
-
317
250
# shellcheck disable=SC1007
318
251
local _stty_height= _stty_width=
319
252
read -r _stty_height _stty_width <<(
320
-
ifstty size&>/dev/null;then
253
+
ifcommand -v stty&>/dev/null;then
321
254
stty size
322
255
else
323
-
if [ -n"$COLUMNS" ];then
324
-
printf'%s\n'"20 $COLUMNS"
325
-
else
326
-
printf'%s\n''20 80'
327
-
fi
256
+
printf'%s\n''20 80'
328
257
fi
329
258
)
330
259
@@ -366,20 +295,11 @@ __bake_parse_args() {
366
295
__bake_internal_die "Specified file '$BAKE_FILE' is not actually a file"
0 commit comments