-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentinel2
More file actions
executable file
·129 lines (122 loc) · 4.42 KB
/
Copy pathsentinel2
File metadata and controls
executable file
·129 lines (122 loc) · 4.42 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
#!/usr/bin/env bash
# Domain CLI dispatcher — a tiny `fw`-style front door for ONE fwh_* domain.
#
# Auto-discovers this package's terminal tools (src/<pkg>/tools/*.sh) and its FFL
# workflows, and dispatches to a tool by name. The filesystem is the registry —
# drop a new `tools/<name>.sh` in and it shows up here automatically.
#
# ./<this> help # or no args / --help : the menu of common operations
# ./<this> <command> ... # run tools/<command>.sh with the given args
#
# Identical across every fwh_* repo; only the filename differs (osm, save-earth,
# census, …). Tools run in the terminal; workflows run on the runtime via `fw`.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SELF="$(basename "${BASH_SOURCE[0]}")"
PKG="$(ls "$ROOT/src" 2>/dev/null | grep -v '\.egg-info$' | head -1)"
PKGDIR="$ROOT/src/$PKG"
TOOLS="$PKGDIR/tools"
# First line of a Python module docstring — handles BOTH single-line
# ("""text""") and multi-line docstrings, and a leading shebang.
_py_summary() {
awk '
!found {
i = index($0, "\"\"\"")
if (i > 0) {
rest = substr($0, i + 3)
j = index(rest, "\"\"\"") # closing """ on the same line?
if (j > 0) rest = substr(rest, 1, j - 1)
gsub(/^[[:space:]]+/, "", rest); gsub(/[[:space:]]+$/, "", rest)
if (rest ~ /[^[:space:]]/) { print rest; exit }
found = 1; next # text is on the following line
}
next
}
found {
l = $0; sub(/"""/, "", l)
gsub(/^[[:space:]]+/, "", l); gsub(/[[:space:]]+$/, "", l)
print l; exit
}' "$1" 2>/dev/null | head -1
}
# Summary for one tool: (1) paired .py docstring, (2) for an all-* batch wrapper,
# the base tool's docstring prefixed "All cached regions:", (3) an explicit
# "# summary:" header line in the .sh itself.
_tool_summary() {
local name="$1" py base bpy sum=""
py="$TOOLS/$(echo "$name" | tr '-' '_').py"
[ -f "$py" ] && sum="$(_py_summary "$py")"
if [ -z "$sum" ] && [ "${name#all-}" != "$name" ]; then
base="${name#all-}"
bpy="$TOOLS/$(echo "$base" | tr '-' '_').py"
[ -f "$bpy" ] && sum="All cached regions: $(_py_summary "$bpy")"
fi
[ -z "$sum" ] && sum="$(sed -n 's/^#[[:space:]]*summary:[[:space:]]*//p' "$TOOLS/$name.sh" 2>/dev/null | head -1)"
echo "$sum"
}
_list_tools() {
[ -d "$TOOLS" ] || return 0
for sh in "$TOOLS"/*.sh; do
[ -e "$sh" ] || continue
name="$(basename "$sh" .sh)"; case "$name" in _*) continue;; esac
printf ' %-28s %s\n' "$name" "$(_tool_summary "$name")"
done
}
_list_workflows() {
# ns.Workflow → the fw ffl run line. Capped so big domains (osm) stay readable.
local n=0
while IFS=$'\t' read -r wf ffl; do
[ -n "$wf" ] || continue
n=$((n + 1))
if [ "$n" -le 18 ]; then
tl="${wf%%.*}"
rel="${ffl#"$ROOT"/}"
printf ' %s\n fw ffl run --primary %s --workflow %s --task-list %s\n' "$wf" "$rel" "$wf" "$tl"
fi
done < <(
find "$PKGDIR" -name '*.ffl' 2>/dev/null | sort | while read -r f; do
awk '
/^[[:space:]]*namespace[[:space:]]+/ { ns=$2 }
/^[[:space:]]*workflow[[:space:]]+/ { name=$2; sub(/\(.*/, "", name); print ns "." name "\t" FILENAME }
' "$f"
done
)
if [ "$n" -gt 18 ]; then
printf ' ... and %d more (see %s/**/*.ffl)\n' "$((n - 18))" "src/$PKG"
fi
}
_help() {
echo "$SELF — the '$PKG' Facetwork domain CLI"
echo
echo "USAGE"
echo " ./$SELF <command> [args...] run a terminal tool (see the list below)"
echo " ./$SELF help show this menu"
echo
if [ -d "$TOOLS" ]; then
echo "TOOLS (terminal CLIs — operate the local/MinIO cache directly)"
_list_tools
echo
else
echo "(this domain ships no terminal tools — its operations are FFL workflows)"
echo
fi
echo "WORKFLOWS (run on the Facetwork runtime; dashboard-visible)"
_list_workflows
echo
echo "Storage: prefix tool runs with FW_STORAGE=s3 FW_DATA_ROOT=s3://afl-cache"
echo " FW_S3_ENDPOINT=http://afl-minio:9000 (… ACCESS_KEY/SECRET_KEY) to use the fleet cache."
}
cmd="${1:-help}"
case "$cmd" in
help | -h | --help | "") _help ;;
*)
tool="$TOOLS/$cmd.sh"
[ -f "$tool" ] || tool="$TOOLS/$(echo "$cmd" | tr '_' '-').sh"
if [ -f "$tool" ]; then
shift
exec "$tool" "$@"
fi
echo "$SELF: unknown command '$cmd'" >&2
echo "Run './$SELF help' for the list of tools + workflows." >&2
exit 2
;;
esac