16
16
# 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,12 +91,12 @@ bake.assert_cmd() {
91
91
fi
92
92
}
93
93
94
- # @description Change the behavior of Bake. See [guide.md](./docs/guide.md) for details
94
+ # @description Change the behavior of Bake
95
95
# @arg $1 string Name of config property to change
96
96
# @arg $2 string New value of config property
97
97
bake.cfg () {
98
- local cfg=" $1 "
99
- local value=" $2 "
98
+ local cfg=$1
99
+ local value=$2
100
100
101
101
case $cfg in
102
102
stacktrace)
@@ -112,12 +112,6 @@ bake.cfg() {
112
112
* ) __bake_internal_die2 " Config property '$cfg ' accepts only either 'yes' or 'no'" ;;
113
113
esac
114
114
;;
115
- big-print)
116
- case $value in
117
- yes|no) ;;
118
- * ) __bake_internal_die2 " Config property '$cfg ' accepts only either 'yes' or 'no'" ;;
119
- esac
120
- ;;
121
115
* )
122
116
__bake_internal_die2 " No config property matched '$cfg '"
123
117
;;
@@ -236,27 +230,15 @@ __bake_error() {
236
230
# @description Nicely prints all 'Bakefile.sh' tasks to standard output
237
231
# @internal
238
232
__bake_print_tasks () {
239
- printf ' %s\n' ' Tasks:'
240
- local str=
241
-
242
233
# shellcheck disable=SC1007,SC2034
243
234
local regex=" ^(([[:space:]]*function[[:space:]]*)?task\.(.*?)\(\)).*"
244
235
local line=
236
+ printf ' %s\n' ' Tasks:'
245
237
while IFS= read -r line || [ -n " $line " ]; do
246
238
if [[ " $line " =~ $regex ]]; then
247
- str+= " -> ${BASH_REMATCH[3]} " $' \n '
239
+ printf ' %s\n ' " -> ${BASH_REMATCH[3]} "
248
240
fi
249
241
done < " $BAKE_FILE " ; unset -v line
250
-
251
- if [ -z " $str " ]; then
252
- if __bake_is_color; then
253
- str=$' \033 [3mNo tasks\033 [0m\n '
254
- else
255
- str=$' No tasks\n '
256
- fi
257
- fi
258
-
259
- printf ' %s' " $str "
260
242
} >&2
261
243
262
244
# @description Prints text that takes up the whole terminal width
@@ -265,21 +247,13 @@ __bake_print_tasks() {
265
247
__bake_print_big () {
266
248
local print_text=" $1 "
267
249
268
- if [ " $__bake_cfg_big_print " = ' no' ]; then
269
- return
270
- fi
271
-
272
250
# shellcheck disable=SC1007
273
251
local _stty_height= _stty_width=
274
252
read -r _stty_height _stty_width < <(
275
- if stty size & > /dev/null; then
253
+ if command -v stty & > /dev/null; then
276
254
stty size
277
255
else
278
- if [ -n " $COLUMNS " ]; then
279
- printf ' %s\n' " 20 $COLUMNS "
280
- else
281
- printf ' %s\n' ' 20 80'
282
- fi
256
+ printf ' %s\n' ' 20 80'
283
257
fi
284
258
)
285
259
@@ -302,7 +276,6 @@ __bake_parse_args() {
302
276
unset REPLY; REPLY=
303
277
local -i total_shifts=0
304
278
305
- # FIXME: bug for when passing -v to child task argument
306
279
local __bake_arg=
307
280
for arg; do case $arg in
308
281
-f)
@@ -322,10 +295,6 @@ __bake_parse_args() {
322
295
__bake_internal_die " Specified file '$BAKE_FILE ' is not actually a file"
323
296
fi
324
297
;;
325
- -v)
326
- local bake_version=' 1.8.2'
327
- printf ' %s\n' " Version: $bake_version "
328
- ;;
329
298
-h)
330
299
local flag_help=' yes'
331
300
if ! shift ; then
@@ -342,7 +311,7 @@ __bake_parse_args() {
342
311
BAKE_FILE=" $BAKE_ROOT /${BAKE_FILE##*/ } "
343
312
else
344
313
if ! BAKE_ROOT=$(
345
- while [ ! -f ' ./ Bakefile.sh' ] && [ " $PWD " != / ]; do
314
+ while [ ! -f ' Bakefile.sh' ] && [ " $PWD " != / ]; do
346
315
if ! cd ..; then
347
316
exit 1
348
317
fi
@@ -360,8 +329,8 @@ __bake_parse_args() {
360
329
fi
361
330
362
331
if [ " $flag_help " = ' yes' ]; then
363
- cat << -" EOF "
364
- Usage: bake [-h|-v ] [-f <Bakefile>] [var=value ...] <task> [args ...]
332
+ cat << -EOF
333
+ Usage: bake [-h] [-f <Bakefile>] [var=value ...] <task> [args ...]
365
334
EOF
366
335
__bake_print_tasks
367
336
exit
@@ -374,27 +343,22 @@ __bake_parse_args() {
374
343
# @internal
375
344
__bake_main () {
376
345
__bake_cfg_stacktrace=' no'
377
- __bake_cfg_big_print=' yes'
378
346
379
- # Environment boilerplate
380
347
set -ETeo pipefail
381
348
shopt -s dotglob extglob globasciiranges globstar lastpipe shift_verbose
382
- export LANG=' C' LC_CTYPE=' C' LC_NUMERIC=' C' LC_TIME=' C' LC_COLLATE=' C' \
383
- LC_MONETARY =' C' LC_MESSAGES =' C' LC_PAPER =' C' LC_NAME =' C' LC_ADDRESS =' C' \
384
- LC_TELEPHONE= ' C ' LC_MEASUREMENT=' C' LC_IDENTIFICATION=' C' LC_ALL=' C'
349
+ export LANG=' C' LC_CTYPE=' C' LC_NUMERIC=' C' LC_TIME=' C' LC_COLLATE=' C' LC_MONETARY= ' C ' \
350
+ LC_MESSAGES =' C' LC_PAPER =' C' LC_NAME =' C' LC_ADDRESS =' C' LC_TELEPHONE =' C' \
351
+ LC_MEASUREMENT=' C' LC_IDENTIFICATION=' C' LC_ALL=' C'
385
352
trap ' __bake_trap_err' ' ERR'
386
- trap ' :' ' INT' # Ensure Ctrl-C ends up printing <- ERROR ==== etc.
387
353
bake.cfg pedantic-task-cd ' no'
388
354
389
- # Parse arguments
390
355
# Set `BAKE_{ROOT,FILE}`
391
356
BAKE_ROOT=; BAKE_FILE=
392
357
__bake_parse_args " $@ "
393
358
if ! shift " $REPLY " ; then
394
359
__bake_internal_die ' Failed to shift'
395
360
fi
396
361
397
- # Set variables à la Make
398
362
# shellcheck disable=SC1007
399
363
local __bake_key= __bake_value=
400
364
local __bake_arg=
@@ -412,8 +376,8 @@ __bake_main() {
412
376
;;
413
377
* ) break
414
378
esac done ; unset -v __bake_arg
379
+ # Note: Don't unset '__bake_variable' or none of the variables will stay set
415
380
unset -v __bake_key __bake_value
416
- unset -vn __bake_variable
417
381
418
382
local __bake_task=" $1 "
419
383
if [ -z " $__bake_task " ]; then
@@ -433,21 +397,6 @@ __bake_main() {
433
397
__bake_task= source " $BAKE_FILE "
434
398
435
399
if declare -f task." $__bake_task " > /dev/null 2>&1 ; then
436
- local line=
437
- local shouldTestNextLine=' no'
438
- while IFS= read -r line; do
439
- if [ " $shouldTestNextLine " = ' yes' ]; then
440
- if [[ $line == * ' bake.cfg' * big-print* no* ]]; then
441
- __bake_cfg_big_print=' no'
442
- fi
443
- shouldTestNextLine=' no'
444
- fi
445
-
446
- if [[ $line == @ (task." $__bake_task " | init)* ' (' * ' )' * ' {' ]]; then
447
- shouldTestNextLine=' yes'
448
- fi
449
- done < " $BAKE_FILE " ; unset -v line shouldTestNextLine
450
-
451
400
__bake_print_big " -> RUNNING TASK '$__bake_task '"
452
401
if declare -f init > /dev/null 2>&1 ; then
453
402
init " $__bake_task "
0 commit comments