fix(utils): improve get_function_description file resolution (#122)

This commit is contained in:
2025-06-11 21:16:42 +03:00
parent 6155891fa4
commit 5a832d1478

View File

@@ -663,19 +663,27 @@ main::get_command_functions()
# the description text. If no description is found, nothing is printed. # the description text. If no description is found, nothing is printed.
# #
# Arguments: # Arguments:
# cmd_file - Path to the file containing the function definitions. # cmd - Command name or path to the file containing the function definitions.
# func - Name of the function whose description is to be extracted. # func - Name of the function whose description is to be extracted.
# #
# Outputs: # Outputs:
# The extracted description text is printed to STDOUT. # The extracted description text is printed to STDOUT.
# #
# Example: # Example:
# desc=$(main::get_function_description "/path/to/commands.sh" "my_function") # desc=$(main::get_function_description "install" "my_function")
main::get_function_description() main::get_function_description()
{ {
local cmd_file="$1" local cmd="$1"
local cmd_file="${DFM_CMD_DIR}/${cmd}.sh"
local func="$2" local func="$2"
local cmd_file="${DFM_CMD_DIR}/${cmd}.sh"
if [[ ! -f "$cmd_file" && -f "$cmd" ]]; then
cmd_file="$cmd"
fi
if [[ ! -f "$cmd_file" ]]; then
return 1
fi
grep -B1 "^[[:space:]]*\(function[[:space:]]*\)\{0,1\}$func().*{" "$cmd_file" \ grep -B1 "^[[:space:]]*\(function[[:space:]]*\)\{0,1\}$func().*{" "$cmd_file" \
| grep "@description" \ | grep "@description" \