-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnebula
64 lines (55 loc) · 1.46 KB
/
nebula
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
#!/bin/sh
help() {
echo "See our documentation: https://foxservers.net/documentation/nebula"
}
# List of valid namespaces
valid_namespaces=("add" "init" "reload" "remove" "update")
# Declare hooks dynamically based on valid namespaces
for namespace in "${valid_namespaces[@]}"; do
declare -a "${namespace}_hooks=()"
done
# Dynamic hook invoking
invoke_hooks() {
local hooks_array_name="$1"
shift
local -n hooks_array="$hooks_array_name"
for hook in "${hooks_array[@]}"; do
$hook "$@"
done
}
# Dynamic hook invoking
register_hook() {
local hooks_array_name="$1"
local hook_function="$2"
local -n hook_array="$hooks_array_name"
hook_array+=("$hook_function")
}
# Loop to dynamically define functions
for namespace in "${valid_namespaces[@]}"; do
eval "$namespace() { invoke_hooks \"${namespace}_hooks\" \"\$@\"; }"
done
for directory in /opt/nebula/core/bin/ /opt/nebula/extensions/*/bin/; do
for file in "$directory"/*; do
if [ -f "$file" ]; then
source "$file"
fi
done
done
# Function to handle calls
main() {
local namespace=$1
shift
if [[ " ${valid_namespaces[@]} " == *" $namespace "* ]]; then
"$namespace" "$@"
else
local function=$1
shift
local full_function="${namespace}_${function}"
if declare -f "$full_function" > /dev/null; then
"$full_function" "$@"
else
help
fi
fi
}
main "$@"