-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathye-bash4.sh
More file actions
executable file
·706 lines (586 loc) · 18.4 KB
/
ye-bash4.sh
File metadata and controls
executable file
·706 lines (586 loc) · 18.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
#!/bin/bash
########################################
# Beats Ye-Bash4 Framework #
# http://github.com/Beats/ye-bash4 #
########################################
[ ${BASH_VERSINFO[0]} -lt 4 ] && >&2 echo "Requires Bash v4" && exit 2
[ "$0" != "$BASH_SOURCE" ]
YE_BASH4_BUILDER=$?
YE_BASH4_SCRIPT_FILE=$(cd `dirname "$0"` && pwd)/`basename "$0"`
YE_BASH4_SCRIPT_NAME=${YE_BASH4_SCRIPT_FILE##*/}
YE_BASH4_SCRIPT_HOME=${YE_BASH4_SCRIPT_FILE%/*}
YE_BASH4_SCRIPT_VERSION="0.1"
##
# Constants
##
declare -r YE_BASH4_VERSION="0.1"
declare -r YE_BASH4_TYPE_F=-1
declare -r YE_BASH4_TYPE_C=-2
declare -r YE_BASH4_TYPE_A=1
declare -r YE_BASH4_TYPE_P=2
##
# Parameters
##
declare -A YE_BASH4_PARAMETER
declare -A YE_BASH4_PARAMETER_TYPE
declare -A YE_BASH4_OPTIONS
declare -A YE_BASH4_OPTION_USAGE
declare -a YE_BASH4_COMPONENT_C
declare -a YE_BASH4_COMPONENT_F
declare -a YE_BASH4_COMPONENT_P
declare -a YE_BASH4_ARGS
YE_BASH4_COMMAND=
YE_BASH4_DEFAULT="ye_bash4_usage"
##
# Utilities
##
ye_bash4_is_function() {
declare -f "$1" > /dev/null;
return $((1 -$?))
}
ye_bash4_parse_register_args() {
local arg
for arg in "$@"; do
case "$arg" in
--*) __optL="$arg";;
-*) __optS="$arg";;
*) __text="$arg";;
esac
done
}
ye_bash4_register_C() {
local __name="$1"
local __optS=""
local __optL=""
local __text=""
shift;
ye_bash4_parse_register_args "$@"
ye_bash4_register "$YE_BASH4_TYPE_C" "$__name" "$__optS" "$__optL" "$__text"
}
ye_bash4_register_F() {
local __name="$1"
local __optS=""
local __optL=""
local __text=""
shift;
ye_bash4_parse_register_args "$@"
ye_bash4_register "$YE_BASH4_TYPE_F" "$__name" "$__optS" "$__optL" "$__text"
}
ye_bash4_register_P() {
local __name="$1"
local __optS=""
local __optL=""
local __text=""
shift;
ye_bash4_parse_register_args "$@"
ye_bash4_register "$YE_BASH4_TYPE_P" "$__name" "$__optS" "$__optL" "$__text"
}
ye_bash4_register() {
local __type="$1"
local __name="$2"
local __optS="$3"
local __optL="$4"
local __text="$5"
ye_bash4_normalize_options() {
local __optS="$1"
local __optL="$2"
local __delimiter="$3"
if [ -z "$__delimiter" ]; then
__delimiter="|"
fi
if [ -z "$__optS" ]; then
printf "%s" "$__optL"
elif [ -z "$__optL" ]; then
printf "%s" "$__optS"
else
printf "%s" "$__optS$__delimiter$__optL"
fi
}
ye_bash4_format_usage() {
local __optS="$1"
local __optL="$2"
local __text="$3"
local __opts=`ye_bash4_normalize_options "$__optS" "$__optL" ", "`
echo -e " $__opts\n $__text\n"
}
if [ -z "$__optS" -a -z "$__optL" ]; then
>&2 echo "Invalid option registration for: $__name"
exit 1;
fi
case "$__type" in
"$YE_BASH4_TYPE_C")
YE_BASH4_COMPONENT_C+=($__name)
;;
"$YE_BASH4_TYPE_F")
YE_BASH4_COMPONENT_F+=($__name)
;;
"$YE_BASH4_TYPE_P")
YE_BASH4_COMPONENT_P+=($__name)
;;
esac
YE_BASH4_PARAMETER[$__name]="`ye_bash4_normalize_options "$__optS" "$__optL"`"
YE_BASH4_PARAMETER_TYPE[$__name]=$__type
YE_BASH4_OPTION_USAGE[$__name]="`ye_bash4_format_usage "$__optS" "$__optL" "$__text"`
"
unset -f ye_bash4_normalize_options
}
###############################
# Ye-Bash4 Framework Engine #
###############################
##
# Processes the registered components
##
ye_bash4_registration_processor() {
ye_bash4_register_defaults() {
##
# Flags
##
ye_bash4_register $YE_BASH4_TYPE_F "YE_BASH4_VERBOSE" "-v" "--verbose" "Explain what is being done"
YE_BASH4_VERBOSE=0
ye_bash4_register $YE_BASH4_TYPE_F "YE_BASH4_DEBUG" "" "--debug" "Display debugging information"
YE_BASH4_DEBUG=0
##
# Commands
##
ye_bash4_register $YE_BASH4_TYPE_C "ye_bash4_version" "" "--version" "Display the script version"
ye_bash4_is_function "ye_bash4_version"
if [ $? -eq 0 ]; then
ye_bash4_version() {
echo "$YE_BASH4_SCRIPT_NAME v$YE_BASH4_SCRIPT_VERSION"
echo
}
fi
ye_bash4_register $YE_BASH4_TYPE_C "ye_bash4_usage" "-h" "--help" "Display this usage text"
ye_bash4_is_function "ye_bash4_usage"
if [ $? -eq 0 ]; then
ye_bash4_usage() {
local __name=
echo "Usage: $YE_BASH4_SCRIPT_NAME"
echo "Options:"
for __name in "${YE_BASH4_COMPONENT_P[@]}"; do
echo "${YE_BASH4_OPTION_USAGE[$__name]}"
done
for __name in "${YE_BASH4_COMPONENT_F[@]}"; do
echo "${YE_BASH4_OPTION_USAGE[$__name]}"
done
for __name in "${YE_BASH4_COMPONENT_C[@]}"; do
echo "${YE_BASH4_OPTION_USAGE[$__name]}"
done
}
fi
ye_bash4_is_function "ye_bash4_debug"
if [ $? -eq 0 ]; then
ye_bash4_debug() {
local __i=0
local __name=
echo "$YE_BASH4_SCRIPT_NAME: $YE_BASH4_SCRIPT_VERSION"
echo "Beats Ye-Bash4: $YE_BASH4_VERSION"
echo "Command: $YE_BASH4_COMMAND"
echo "Flags:"
for __name in "${YE_BASH4_COMPONENT_F[@]}"; do
echo -n " $__name:"; eval echo \$$__name
done
echo "Parameters:"
for __name in "${YE_BASH4_COMPONENT_P[@]}"; do
echo -n " $__name:"; eval echo \$$__name
done
echo "Arguments:"
for __name in "${YE_BASH4_ARGS[@]}"; do
echo " YE_BASH_ARGS[$__i]:$__name"; ((__i++));
done
if [ $YE_BASH4_VERBOSE -ne 0 ]; then
echo "Script:"
echo " Name: $YE_BASH4_SCRIPT_NAME"
echo " Home: $YE_BASH4_SCRIPT_HOME"
echo " File: $YE_BASH4_SCRIPT_FILE"
fi;
}
fi
if [ "$YE_BASH4_BUILDER" -eq 0 ]; then
unset -f ye_bash4_is_function ye_bash4_format_usage
unset -f ye_bash4_parse_register_args ye_bash4_register ye_bash4_register_C ye_bash4_register_F ye_bash4_register_P
fi
}
ye_bash4_register_defaults
unset -f ye_bash4_register_defaults
ye_bash4_component_builder() {
ye_bash4_join() {
local IFS="$1"; shift; echo "$*";
}
ye_bash4_getopt_option_builder() {
local __component=$1
local __opts=$2
local __handler=$3
local __modifier=$4
local __option=
local __options=(${__opts//\|/ })
for __option in "${__options[@]}"; do
YE_BASH4_OPTIONS[$__option]="$__component|$__handler"
case "$__option" in
-?)
YE_BASH4_OPTS_S+=("${__option:1}$__modifier")
;;
--*)
YE_BASH4_OPTS_L+=("${__option:2}$__modifier")
;;
esac
done
}
ye_bash4_component_processor() {
local __component=$1
local __opts=$2
local __type=$3
local __handler=
local __modifier=""
case "$__type" in
"$YE_BASH4_TYPE_C")
__handler="ye_bash4_action"
__modifier=""
;;
"$YE_BASH4_TYPE_F")
__handler="ye_bash4_flag"
__modifier=""
;;
"$YE_BASH4_TYPE_P")
__handler="ye_bash4_parameter"
__modifier=":"
;;
esac
ye_bash4_getopt_option_builder "$__component" "$__opts" "$__handler" "$__modifier"
}
local __key=
for __key in "${!YE_BASH4_PARAMETER[@]}"; do
ye_bash4_component_processor "$__key" "${YE_BASH4_PARAMETER[$__key]}" "${YE_BASH4_PARAMETER_TYPE[$__key]}"
done
YE_BASH4_OPTS_S=`ye_bash4_join "" "${YE_BASH4_OPTS_S[@]}"`
YE_BASH4_OPTS_L=`ye_bash4_join , "${YE_BASH4_OPTS_L[@]}"`
unset -f ye_bash4_join ye_bash4_getopt_option_builder ye_bash4_component_processor
unset -v YE_BASH4_PARAMETER YE_BASH4_PARAMETER_TYPE
}
local YE_BASH4_OPTS_L=()
local YE_BASH4_OPTS_S=()
ye_bash4_component_builder
YE_BASH4_GETOPT="getopt -o "$YE_BASH4_OPTS_S" -l "$YE_BASH4_OPTS_L" -n "$YE_BASH4_SCRIPT_NAME" --"
unset -f ye_bash4_component_builder
unset -v YE_BASH4_OPTS_L YE_BASH4_OPTS_S
}
##
# Parses the user provided input
#
ye_bash4_input_parser() {
YE_BASH4_GETOPT=`$YE_BASH4_GETOPT "$@"`
if [ $? -ne 0 ]; then
ye_bash4_usage
exit 1
fi
ye_bash4_input_processor() {
eval set -- "$YE_BASH4_GETOPT"
ye_bash4_action() {
if [ -z "$YE_BASH4_COMMAND" ]; then
YE_BASH4_COMMAND="$1"
return 1
else
YE_BASH4_COMMAND="ye_bash4_usage"
return 0
fi
}
ye_bash4_parameter() {
local __name=$1
if [ ! -z "$2" ]; then
eval "$__name=\"$2\""
fi
return 2
}
ye_bash4_flag() {
local __param=$1
eval $__param=$((1 - $__param))
return 1
}
ye_bash4_option_handler() {
local __option="$1"
local __return=0
local __pattern=${YE_BASH4_OPTIONS["$__option"]}
local __options=(${__pattern//\|/ })
local __component=${__options[0]}
local __handler=${__options[1]}
$__handler $__component "$2"
__return=$?
unset YE_BASH4_OPTIONS[$__option]
return $__return
}
local __loop=
while true; do
if [[ "$1" == "--" ]]; then
shift
break
fi
ye_bash4_option_handler "$1" "$2"
__loop=$?
if [ $__loop -gt 0 ]; then
shift $__loop
elif [ $__loop -eq 0 ]; then
break
fi
done
for __loop do
YE_BASH4_ARGS+=("$__loop")
done
unset -f ye_bash4_action ye_bash4_flag ye_bash4_parameter ye_bash4_option_handler
if [ -z "$YE_BASH4_COMMAND" ]; then
YE_BASH4_COMMAND="$YE_BASH4_DEFAULT"
fi
}
ye_bash4_input_processor
unset -f ye_bash4_input_processor
if [ $YE_BASH4_DEBUG -ne 0 ]; then
ye_bash4_debug
exit 0
fi
}
##
# Interpreter
##
ye_bash4_interpreter() {
local YE_BASH4_GETOPT
ye_bash4_registration_processor
if [ "$YE_BASH4_BUILDER" -eq 0 ]; then
unset -f ye_bash4_registration_processor
fi
unset -f ye_bash4_interpreter
ye_bash4_executor "$@"
}
##
# Executor
##
ye_bash4_executor() {
ye_bash4_input_parser "$@"
unset -v YE_BASH4_GETOPT
if [ "$YE_BASH4_BUILDER" -eq 0 ]; then
unset -f ye_bash4_input_parser
unset -v YE_BASH4_OPTIONS
unset -f ye_bash4_interpreter ye_bash4_executor
fi
$YE_BASH4_COMMAND
ye_bash4_collect_garbage() {
local __name
for __name in "${YE_BASH4_COMPONENT_P[@]}"; do
unset -v "$__name"
done
for __name in "${YE_BASH4_COMPONENT_F[@]}"; do
unset -v "$__name"
done
for __name in "${YE_BASH4_COMPONENT_C[@]}"; do
unset -f "$__name"
done
}
ye_bash4_collect_garbage
unset -f ye_bash4_collect_garbage
unset -f ye_bash4_usage ye_bash4_debug ye_bash4_version
unset -v YE_BASH4_OPTION_USAGE
unset -v YE_BASH4_COMMAND YE_BASH4_ARGS YE_BASH4_DEBUG YE_BASH4_VERBOSE
unset -v YE_BASH4_SCRIPT_FILE YE_BASH4_SCRIPT_NAME YE_BASH4_SCRIPT_HOME YE_BASH4_SCRIPT_VERSION
unset -v YE_BASH4_COMPONENT_C YE_BASH4_COMPONENT_F YE_BASH4_COMPONENT_P
}
if [ "$YE_BASH4_BUILDER" -ne 0 ]; then
ye_bash4_confirm() {
if [ "${2:-0}" -ne 0 ]; then
return 0
fi
read -r -p "${1:-Are you sure?} [y/N] " response
case $response in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
ye_bash4_target_comment() {
local __target="$1"
sed -i "/$2/ s:^:#yb4#:" "$__target"
}
ye_bash4_target_reset() {
local __target="$1"
local __source="$2"
if [ ! -z "$__source" ]; then
cp $__target $__source
__target="$__source"
fi
sed -i '/^#yb4##yb4##yb4##yb4##yb4##yb4#$/,$d' $__target
sed -i 's/#yb4#//g' $__target
sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' $__target
}
ye_bash4_target_build() {
local __target="${YE_BASH4_ARGS[1]}"
local __source="${YE_BASH4_ARGS[0]}"
if [ ! -f "$__source" ]; then
>&2 echo "The source file doesn't exist: $__source"
exit 2;
fi
if [ ! -r "$__source" ]; then
>&2 echo "The source file is not readable: $__source"
exit 2;
fi
__source=$(cd `dirname "$__source"` && pwd)/`basename "$__source"`
if [ "$YE_BASH4_SCRIPT_FILE" == "$__source" ]; then
>&2 echo "Are you really that crazy, trying to build a file from the framework source: $__source"
exit 2;
fi
if [ -f "$__target" ]; then
__target=$(cd `dirname "$__target"` && pwd)/`basename "$__target"`
if [ "$YE_BASH4_SCRIPT_FILE" == "$__target" ]; then
>&2 echo "Are you really that crazy, trying to overwrite the framework: $__target"
exit 2;
fi
ye_bash4_confirm "Are your sure you want to overwrite the file: $__target?" $YE_BASH4_AUTOCONFIRM
if [ "$?" -ne 0 ]; then
exit 0;
fi
else
touch "$__target" > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
>&2 echo "The target file can't be created: $__target"
exit 2;
fi
__target=$(cd `dirname "$__target"` && pwd)/`basename "$__target"`
fi
echo "Building '$__target' script from '$__source'"
cp $__source $__target
ye_bash4_target_escape() {
local __target="$1"
local __step="$2"
case $__step in
0)
ye_bash4_target_comment $__target '^\s*ye_bash4_interpreter.*$'
ye_bash4_target_comment $__target '^\s*\(source\|\.\)\s.*ye-bash4\.sh.*$'
;;
1)
ye_bash4_target_comment $__target '^\s*ye_bash4_register.*$'
ye_bash4_target_comment $__target '^\s*YE_BASH4_SCRIPT_VERSION.*$'
;;
esac
}
ye_bash4_target_escape $__target 0
unset -v YE_BASH4_COMPONENT_C YE_BASH4_COMPONENT_F YE_BASH4_COMPONENT_P
unset -v YE_BASH4_PARAMETER YE_BASH4_PARAMETER_TYPE
unset -v YE_BASH4_OPTION_USAGE YE_BASH4_OPTIONS
declare -A YE_BASH4_OPTIONS
declare -A YE_BASH4_OPTION_USAGE
declare -A YE_BASH4_PARAMETER
declare -A YE_BASH4_PARAMETER_TYPE
declare -a YE_BASH4_COMPONENT_C
declare -a YE_BASH4_COMPONENT_F
declare -a YE_BASH4_COMPONENT_P
local YE_BASH4_GETOPT=
source $__target
YE_BASH4_SCRIPT_FILE=$__target
YE_BASH4_SCRIPT_NAME=${YE_BASH4_SCRIPT_FILE##*/}
ye_bash4_registration_processor
ye_bash4_target_escape $__target 1
unset -f ye_bash4_target_escape
declare -a YE_BASH4_DEFAULT_COMMANDS
ye_bash4_is_overridden() {
local __command="$2"
local __count=`grep -Pc "^(\s*)(function)?(\s*)?$__command\s*(\(\))?\s*{" $1`
if [[ $__count -eq 0 ]]; then
YE_BASH4_DEFAULT_COMMANDS+=("$__command")
fi
return $__count
}
ye_bash4_is_overridden "$__target" 'ye_bash4_usage'
ye_bash4_is_overridden "$__target" 'ye_bash4_debug'
ye_bash4_is_overridden "$__target" 'ye_bash4_version'
unset -f ye_bash4_is_overridden
echo >> $__target
echo >> $__target
echo "#yb4##yb4##yb4##yb4##yb4##yb4##yb4##yb4#" >> $__target
echo "########################################" >> $__target
echo "# Beats Ye-Bash4 Framework #" >> $__target
echo "# http://github.com/Beats/ye-bash4 #" >> $__target
echo "########################################" >> $__target
echo "#yb4##yb4##yb4##yb4##yb4##yb4##yb4##yb4#" >> $__target
echo "YE_BASH4_BUILDER=0" >> $__target
echo >> $__target
echo 'YE_BASH4_SCRIPT_FILE=$(cd `dirname "$0"` && pwd)/`basename "$0"`' >> $__target
echo 'YE_BASH4_SCRIPT_NAME=${YE_BASH4_SCRIPT_FILE##*/}' >> $__target
echo 'YE_BASH4_SCRIPT_HOME=${YE_BASH4_SCRIPT_FILE%/*}' >> $__target
set | grep ^YE_BASH4_SCRIPT_VERSION >> $__target
echo >> $__target
echo "##" >> $__target
echo "# Constants" >> $__target
echo "##" >> $__target
echo "declare -r YE_BASH4_VERSION='$YE_BASH4_VERSION'" >> $__target
echo >> $__target
echo "declare -r YE_BASH4_TYPE_F=$YE_BASH4_TYPE_F" >> $__target
echo "declare -r YE_BASH4_TYPE_C=$YE_BASH4_TYPE_C" >> $__target
echo "declare -r YE_BASH4_TYPE_A=$YE_BASH4_TYPE_A" >> $__target
echo "declare -r YE_BASH4_TYPE_P=$YE_BASH4_TYPE_P" >> $__target
echo >> $__target
echo "##" >> $__target
echo "# Parameters" >> $__target
echo "##" >> $__target
echo "declare -A YE_BASH4_OPTIONS" >> $__target
echo "declare -A YE_BASH4_OPTION_USAGE" >> $__target
echo >> $__target
echo "declare -A YE_BASH4_COMPONENT_C" >> $__target
echo "declare -A YE_BASH4_COMPONENT_F" >> $__target
echo "declare -A YE_BASH4_COMPONENT_P" >> $__target
echo >> $__target
echo "declare -a YE_BASH4_ARGS" >> $__target
echo "YE_BASH4_COMMAND=" >> $__target
echo >> $__target
set | grep ^YE_BASH4_COMPONENT_C >> $__target
set | grep ^YE_BASH4_COMPONENT_F >> $__target
set | grep ^YE_BASH4_COMPONENT_P >> $__target
echo >> $__target
echo "##" >> $__target
echo "# Flags" >> $__target
echo "##" >> $__target
echo "YE_BASH4_VERBOSE=0" >> $__target
echo "YE_BASH4_DEBUG=0" >> $__target
echo >> $__target
set | grep ^YE_BASH4_GETOPT >> $__target
set | grep ^YE_BASH4_OPTIONS >> $__target
set | grep -Pzo "(?s)^(\s*)YE_BASH4_OPTION_USAGE=\(.*?\" \)$" >> $__target
echo >> $__target
echo "##" >> $__target
echo "# Commands" >> $__target
echo "##" >> $__target
local __name
for __name in "${YE_BASH4_DEFAULT_COMMANDS[@]}"; do
set | grep -Pzo "(?s)^(\s*)$__name\s*\(\).*?{.*?^\1}" >> $__target
echo >> $__target
done
echo "##" >> $__target
echo "# Engine" >> $__target
echo "##" >> $__target
set | grep -Pzo "(?s)^(\s*)ye_bash4_input_processor *\(\).*?{.*?^\1}" >> $__target
echo >> $__target
set | grep -Pzo "(?s)^(\s*)ye_bash4_input_parser *\(\).*?{.*?^\1}" >> $__target
echo >> $__target
set | grep -Pzo "(?s)^(\s*)ye_bash4_executor *\(\).*?{.*?^\1}" >> $__target
echo >> $__target
echo 'ye_bash4_executor "$@"' >> $__target
if [ "$YE_BASH4_CLEAN" -ne 0 ]; then
ye_bash4_confirm "Are you sure you wan't to build a clean script. You wont be able to regenerate the original source?" $YE_BASH4_AUTOCONFIRM
if [ "$?" -eq 0 ]; then
ye_bash4_target_purge() {
local __target="$1"
sed -i '/^#yb4#/d' $__target
}
ye_bash4_target_purge $__target
unset -f ye_bash4_target_purge
fi
fi
echo "Done"
}
YE_BASH4_AUTOCONFIRM=0
ye_bash4_register_F "YE_BASH4_AUTOCONFIRM" "-y" "Assume Yes to all queries and do not prompt"
YE_BASH4_CLEAN=0
ye_bash4_register_F "YE_BASH4_CLEAN" "--clean" "Build a clean (irreversible) script"
ye_bash4_register_C "ye_bash4_target_build" "-b" "--build" "Build a standalone script based on the given source"
ye_bash4_register_C "ye_bash4_target_reset" "-r" "--reset" "Restore the built script to source"
YE_BASH4_DEFAULT="ye_bash4_target_build"
ye_bash4_interpreter "$@"
fi