|
@@ -2,6 +2,31 @@
|
2
|
2
|
|
3
|
3
|
ffoo import pretty
|
4
|
4
|
|
|
5
|
+__valid_pos_int() {
|
|
6
|
+ local val="$1"
|
|
7
|
+ local def="$2"
|
|
8
|
+ if test "$val" -gt 0;
|
|
9
|
+ then
|
|
10
|
+ echo "$val"
|
|
11
|
+ else
|
|
12
|
+ warn "not a positive int, using def: '$def' instead of '$val'"
|
|
13
|
+ echo "$default"
|
|
14
|
+ fi
|
|
15
|
+}
|
|
16
|
+
|
|
17
|
+__valid_int_rule() {
|
|
18
|
+ local rul="$1"
|
|
19
|
+ local def="$2"
|
|
20
|
+ local mocktest="test 0 $rul"
|
|
21
|
+ if bash -n <<<"$mocktest";
|
|
22
|
+ then
|
|
23
|
+ echo "$rul"
|
|
24
|
+ else
|
|
25
|
+ warn "not a valid int rule, using default: '$def' instead of '$rul'"
|
|
26
|
+ echo "$default"
|
|
27
|
+ fi
|
|
28
|
+}
|
|
29
|
+
|
5
|
30
|
|
6
|
31
|
wait_until() {
|
7
|
32
|
#
|
|
@@ -21,17 +46,25 @@ wait_until() {
|
21
|
46
|
# more predictable behavior, limit your command with
|
22
|
47
|
# timeout(1)
|
23
|
48
|
#
|
24
|
|
- local timeout=10
|
25
|
|
- local delay=1
|
26
|
|
- local es_test="-eq 0"
|
|
49
|
+ local delay # delay between polls in s
|
|
50
|
+ local rule # rule to check on exit status (`-eq 0`, `-lt 7`...)
|
|
51
|
+ local timeout # timeout to give up in s
|
|
52
|
+ local usr_delay usr_rule usr_timeout # user given values
|
|
53
|
+ local es_test # to hold final exit status check
|
|
54
|
+ local def_delay=1 # defaults... vv
|
|
55
|
+ local def_rule='-eq 0'
|
|
56
|
+ local def_timeout=10
|
27
|
57
|
while true; do case "$1" in
|
28
|
|
- -x) es_test="-eq $2"; shift; ;;
|
29
|
|
- -X) es_test="$2"; shift; ;;
|
30
|
|
- -d) delay="$2"; shift 2; ;;
|
31
|
|
- -t) timeout="$2"; shift 2; ;;
|
32
|
|
- --) shift 1; break; ;;
|
33
|
|
- *) break; ;;
|
|
58
|
+ -x) usr_rule="-eq $2"; shift; shift ;;
|
|
59
|
+ -X) usr_rule="$2"; shift; shift ;;
|
|
60
|
+ -d) usr_delay="$2"; shift; shift ;;
|
|
61
|
+ -t) usr_timeout="$2"; shift; shift ;;
|
|
62
|
+ --) shift; break ;;
|
|
63
|
+ *) break ;;
|
34
|
64
|
esac done
|
|
65
|
+ delay="$(__valid_pos_int "$usr_delay" "$def_delay")"
|
|
66
|
+ rule="$(__valid_int_rule "$usr_rule" "$def_rule")"
|
|
67
|
+ timeout="$(__valid_pos_int "$usr_timeout" "$def_timeout")"
|
35
|
68
|
think "waiting for: $*"
|
36
|
69
|
local elapsed=0
|
37
|
70
|
local start=$(date +%s)
|
|
@@ -45,7 +78,8 @@ wait_until() {
|
45
|
78
|
"$@";
|
46
|
79
|
es=$?
|
47
|
80
|
debug -v es
|
48
|
|
- if [ $es $es_test ];
|
|
81
|
+ es_test="test $es $rule"
|
|
82
|
+ if eval "$es_test";
|
49
|
83
|
then
|
50
|
84
|
return 0;
|
51
|
85
|
fi
|