Repository navigation
Expand file tree
/
Copy pathrunapi
More file actions
executable file
·72 lines (57 loc) · 1.99 KB
/
Copy pathrunapi
File metadata and controls
executable file
·72 lines (57 loc) · 1.99 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
#!/bin/bash
###############################################################################
#
# runapi
#
# Copyright (c) 2026 Michel MEHL. All rights reserved.
#
# ------------------------------------------------------------------------------
#
# The 'runapi' tool enables to execute directly any function defined in any shell api
# module file
#
# ------------------------------------------------------------------------------
#
# Report bugs to michel.mehl@slashetc.fr
#
###############################################################################
declare -A RUNAPI__VARS
RUNAPI__SOURCEDIRNAME="${BASH_SOURCE[0]%/*}"
RUNAPI__VARS["MYDIR"]="$(readlink -f "${RUNAPI__SOURCEDIRNAME}")"
source "${RUNAPI__VARS["MYDIR"]}/shell-api-core.sh" "runapi"
Runapi__usage() {
cat <<EOF >&2
Usage: $0 <API function name> { <Arguments> }
If a variable needs to be passed as reference, use '.': '. $0 <function> <arguments>'
Example:
. runapi CPU__model mycpu
echo $mycpu # works
EOF
if [ $# -gt 0 ] ; then
echo
echo "Error: $1" >&2
fi
exit -1
}
if [ $# -eq 0 ] ; then
Runapi__usage "Missing function name"
fi
# NOTE: it is not optimized at the moment: all modules are loaded
# A map should be generated giving the module file for the passed function
#
eval $_loadm<<<'shell-api-sys' # process control functions
eval $_loadm<<<'shell-api-dev' # device access functions
eval $_loadm<<<'shell-api-net' # network related functions
eval $_loadm<<<'shell-api-packing' # package management functions (loading)
eval $_loadm<<<'shell-api-yaml' # YAML read/write functions, mandatory core has a dependency on it
eval $_loadm<<<'shell-api-dock'
eval $_loadm<<<'shell-api-mongodb'
eval $_loadm<<<'shell-api-git'
eval $_loadm<<<'shell-api-multimedia'
eval $_loadm<<<'shell-api-xslt'
INVOKED_FUNCTION="$1"
shift
if ! Env__fn_exists "${INVOKED_FUNCTION}" ; then
Runapi__usage "'${INVOKED_FUNCTION}' function is not defined."
fi
"${INVOKED_FUNCTION}" "$@"