feat: add bash shell utility functions
12 funciones Bash del dominio shell: utilidades de scripting (bash_log, bash_colors, bash_check_deps, bash_confirm, bash_handle_error, bash_safe_run), manipulacion de texto (convert_text_case), estructura de proyectos (create_project_structure), y operaciones git (git_clean_branches, git_log_visual, git_push_all_remotes, git_repo_status). Cada una con su .sh y .md de frontmatter.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
# bash_handle_error
|
||||
# -----------------
|
||||
# Muestra un box de error formateado con contexto del fallo.
|
||||
# Incluye script, linea, funcion y directorio.
|
||||
#
|
||||
# USO (sourced):
|
||||
# source bash_handle_error.sh
|
||||
# handle_error "BUILD_FAILED" "La compilacion fallo" "Verifica las dependencias"
|
||||
|
||||
SCRIPT_DIR_BASH_HANDLE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR_BASH_HANDLE/bash_colors.sh"
|
||||
source "$SCRIPT_DIR_BASH_HANDLE/bash_log.sh"
|
||||
bash_colors
|
||||
bash_log_init
|
||||
|
||||
handle_error() {
|
||||
local error_code="$1"
|
||||
local error_description="$2"
|
||||
local solution="$3"
|
||||
|
||||
echo ""
|
||||
echo -e "${RED}╔════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${RED}║ ${CROSS} ERROR DETECTADO ║${NC}"
|
||||
echo -e "${RED}╚════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
echo -e "${RED}${BOLD}Error:${NC} ${error_description}"
|
||||
echo -e "${GRAY}Codigo: ${error_code}${NC}"
|
||||
echo ""
|
||||
|
||||
if [ -n "$solution" ]; then
|
||||
echo -e "${YELLOW}${INFO} Solucion sugerida:${NC}"
|
||||
echo -e " ${solution}"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo -e "${GRAY}${INFO} Informacion adicional:${NC}"
|
||||
echo -e " ${GRAY}${BULLET} Script: ${BASH_SOURCE[2]:-desconocido}${NC}"
|
||||
echo -e " ${GRAY}${BULLET} Linea: ${BASH_LINENO[1]:-desconocido}${NC}"
|
||||
echo -e " ${GRAY}${BULLET} Funcion: ${FUNCNAME[2]:-main}${NC}"
|
||||
echo -e " ${GRAY}${BULLET} Directorio: $(pwd)${NC}"
|
||||
echo -e " ${GRAY}${BULLET} Usuario: $(whoami)${NC}"
|
||||
echo ""
|
||||
|
||||
log "ERROR" "Code: $error_code | Description: $error_description | Script: ${BASH_SOURCE[2]} | Line: ${BASH_LINENO[1]}"
|
||||
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user