#!/bin/bash

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
MAGENTA='\033[0;35m'
RESET='\033[0m'

function execute_command() {
    command="$1"
    message="$2"
    exit_on_failure=${3:-true}

    echo "${GREEN}执行命令：${command}${RESET}"

    eval "${command}"
    status=$?

    if [[ ${status} -ne 0 ]]; then
        echo "${RED}错误：${message}${RESET}"
        if [[ "$exit_on_failure" == "true" ]]; then
            exit ${status}
        else
            return ${status}
        fi
    fi
}
