-
Notifications
You must be signed in to change notification settings - Fork 0
/
poc3.lib.sh
73 lines (66 loc) · 920 Bytes
/
poc3.lib.sh
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
load() { . ./${NAMESPACE:+$NAMESPACE/}$1; }
IN() {
NAMESPACE="$1";
}
GET() {
# GET <name> input
if [ $# -eq 2 ] && [ "$2" = "input" ]; then
load inputs
"$1"
return $?
fi
case "$1" in
(output)
load output
shift
;;
(input)
load inputs
shift
;;
(stdin|-)
if [ $# -ne 1 ]; then
echo >&2 "Wrong syntax: stdin does not support additionnal argument"
return 1
fi
cat
return 0
;;
(*)
load inputs
if ! command >/dev/null 2>&1 -v "$1"; then
echo >&2 "ERROR"
return 1
fi
;;
esac
DefaultOrChain "$@"
}
Chain() {
if [ $# -gt 1 ]; then
local a1="$1";shift
Chain "$a1" | Chain "$@";
return $?
fi
if [ "$1" != : ]; then
"$1";
fi
}
DefaultOrChain() {
if [ $# -eq 0 ]; then
default
return $?
fi
Chain "$@"
}
FILTER() {
load filters
DefaultOrChain "$@"
}
CONVERT() {
load convert
DefaultOrChain "$@"
}
OUTPUT() {
GET output "$@"
}