#!/bin/bash
###############################################################################
# HUMAN-READABLE "BSA BASH SHELL API" and genapp bash app generator
# 
# Copyright (c) 2024-2026 Michel Mehl.
# All rights reserved. 
# Tous droits réservés (France).
# 
# License terms written down in file LICENSE.txt
# Les termes de la licence sont détaillés dans le fichier LICENSE.txt
# 
# Release file path: runapi
# Release file date: 2026-10-25 18:57
# App version: 1.2.0
# App source revision: 267
# App source signature: 540b647815f09cf0725053911324ebd5769fa3805e1136e841f8f4ad60f41700
# Source file last modification: 2026-10-25 17:36:13.953287502 +0100
#
# This header was generated. Do not modify.
#
# ------------------------------------------------------------------------------
#
# The 'runapi' tool enables to execute directly any function defined in any shell api
# module file
#
# ------------------------------------------------------------------------------
# 
# Report bugs and suggestions: 
#     assistance@slashetc.fr
# 
# Specific or corporate requirements or extensions: 
#     info@slashetc.fr
# 
# The author is overall not required to provide maintenance or support  
# outside specific commercial terms agreed.
# 
###############################################################################

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}" "$@"
