#!/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-02 22:15
# App version: 1.1.5
# App source revision: 217
# App source signature: b0abb3ac9aad059ba11052fbb69a62bf38a1db6de26f499d090812db2f982ba7
# Source file last modification: 2026-10-02 21:48:24.079456290 +0200
#
# 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() {
    echo "Usage: $0 <API function name> { <Arguments> }" >&2
    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

eval ${INVOKED_FUNCTION} "$@"
