From a3d8f03b2fcd1d92ec938d558da0b5a874677b8b Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Sep 13 2012 18:29:37 +0000 Subject: Update `Functions/Commons/cli_exportFunctions.sh' file. --- diff --git a/Scripts/Bash/Functions/Commons/cli_exportFunctions.sh b/Scripts/Bash/Functions/Commons/cli_exportFunctions.sh index 4f6aeac..774612f 100755 --- a/Scripts/Bash/Functions/Commons/cli_exportFunctions.sh +++ b/Scripts/Bash/Functions/Commons/cli_exportFunctions.sh @@ -25,45 +25,55 @@ function cli_exportFunctions { - # Define source location where function files are placed in. - local LOCATION=$1 + # Verify the number of arguments passed to this function. + if [[ $# -lt 1 ]];then + cli_printMessage "${FUNCNAME}: `gettext "At least one argument must be passed."`" + fi + + # Retrive export identifier for the function we want to export. + local EXPORTID=$1 + + # Define the source location where function files are placed in. + local LOCATION=${CLI_BASEDIR}/Functions/$(dirname "$EXPORTID") - # Define suffix used to retrive function files. - local SUFFIX=$2 + # Define suffix used to retrieve function files. + local SUFFIX=$(basename "$EXPORTID") - # Verify suffix value used to retrive function files. Assuming no - # suffix value is passed as second argument to this function, use - # the function name value (CLI_FUNCNAME) as default value. + # Verify the suffix value used to retrieve function files. + # Assuming no suffix value is passed as second argument to this + # function, use the function name value (CLI_FUNCNAME) as default + # value. if [[ $SUFFIX == '' ]];then - SUFFIX=$CLI_FUNCNAME + SUFFIX="${CLI_FUNCNAME}[[:alpha:]_]*" fi - # Define pattern used to retrive function names from function + # Define the pattern used to retrieve function names from function # files. - local PATTERN="^function[[:space:]]+${SUFFIX}[[:alnum:]_]*[[:space:]]+{$" + local PATTERN="^function[[:space:]]+${SUFFIX}[[:space:]]+{$" - # Define list of files. + # Define the list of files. local FUNCFILE='' - local FUNCFILES=$(cli_getFilesList ${LOCATION} --pattern="${SUFFIX}.*\.sh" --maxdepth="1") + local FUNCFILES=$(cli_getFilesList ${LOCATION} --pattern="${SUFFIX}\.sh$" \ + --maxdepth="1" --mindepth="1" --type="f") - # Verify list of files. If no function file exists for the + # Verify the list of files. If no function file exists for the # location specified stop the script execution. Otherwise the # script will surely try to execute a function that haven't been # exported yet and report an error about it. if [[ $FUNCFILES == '' ]];then - cli_printMessage "`gettext "No function file was found for this action."`" --as-error-line + cli_printMessage "${FUNCNAME}: `gettext "No function file was found."`" --as-error-line fi - # Process list of files. + # Process the list of files. for FUNCFILE in $FUNCFILES;do - # Verify file execution rights. + # Verify the execution rights for function file. cli_checkFiles $FUNCFILE --execution - # Initialize file. + # Initialize the function file. . $FUNCFILE - # Export function names inside the file to current shell + # Export the function names inside the file to current shell # script environment. export -f $(egrep "${PATTERN}" ${FUNCFILE} | gawk '{ print $2 }')