-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwick-explorer
executable file
·66 lines (51 loc) · 1.6 KB
/
wick-explorer
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
#!/usr/bin/env bash
#
# Run explorers on the target machine.
# Public: Run an explorer.
#
# $1 - Variable name for the result
# $2 - Formula name
# $3 - Explorer name
#
# Returns true when explorer ran successfully, false otherwise.
wickExplorer() {
local cacheKey cacheValue explorer restoreErrors statusCode tempdir
explorer="formulas/$2/explorers/$3"
cacheKey="wick.explorer.$explorer"
if wickKvIsSet "$cacheKey"; then
wickDebug "Explorer is cached: $explorer"
wickKvGet cacheValue "$cacheKey"
local "$1" && wickIndirect "$1" "$cacheValue"
return
fi
if ! wickFind explorer "$explorer"; then
wickError "Unable to find explorer: $explorer"
return 1
fi
wickTempDir tempdir
#: Just like wickStrictRun, this needs to temporarily disable
#: error settings and traps.
restoreErrors="set \"-$-\";$(trap -p ERR)"
# Disable errors only for the subshell and run the explorer.
set +eE
trap "" ERR
(
eval "$restoreErrors"
. "$explorer" > "$tempdir/stdout" 2> "$tempdir/stderr"
)
statusCode=$?
eval "$restoreErrors"
wickDebug "Explorer stdout:"
wickDebug "$(<"$tempdir/stdout")"
wickDebug "Explorer stderr:"
wickDebug "$(<"$tempdir/stderr")"
wickDebug "End of explorer output"
wickKvSet "$cacheKey" "$(<"$tempdir/stdout")"
if [[ "$statusCode" -ne 0 ]]; then
wickError "Explorer failed: $explorer"
wickError "Status code: $statusCode"
return 1
fi
wickDebug "Explorer success"
local "$1" && wickIndirect "$1" "$(<"$tempdir/stdout")"
}