From 8abd7303911c852840a58608c3fe6c3f3b5b9029 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Mon, 14 Apr 2025 11:58:17 +0200 Subject: [PATCH] Ajouter bashlib.sh --- bashlib.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bashlib.sh diff --git a/bashlib.sh b/bashlib.sh new file mode 100644 index 0000000..7dc272b --- /dev/null +++ b/bashlib.sh @@ -0,0 +1,65 @@ +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + + +debug() { + if [[ -n "$DEBUG" ]]; then + local prompt="$1" + shift + local message="$*" + + if [[ -n "$message" ]] ; then + message=": $message" + fi + + echo -e "🐛 \033[0;36m[DEBUG] ${prompt}\033[0m${message}" + fi +} + +error() { + local prompt="$1" + shift + local message="$*" + + if [[ -n "$message" ]] ; then + message=": $message" + fi + + echo -e "${RED}❌ ${prompt}:${NC}${message}" + exit 1 +} + +step() { + local prompt="$1" + shift + local message="$*" + + if [[ -n "$message" ]] ; then + message=": $message" + fi + + echo -e "${YELLOW}🔄 ${prompt}${NC}${message}" +} + +success() { + local prompt="$1" + shift + local message="$*" + + if [[ -n "$message" ]] ; then + message=": $message" + fi + + echo -e "${GREEN}✅ ${prompt}${NC}${message}" +} + +check_command() { + local command="$1" + + if [[ -z $(which ${command}) ]] ; then + error "Missing command" "${command}" + fi +} +