sergehuber commented on code in PR #737:
URL: https://github.com/apache/unomi/pull/737#discussion_r2564970187


##########
build.sh:
##########
@@ -0,0 +1,1118 @@
+#!/bin/bash
+################################################################################
+#
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You under the Apache License, Version 2.0
+#    (the "License"); you may not use this file except in compliance with
+#    the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+################################################################################
+
+set -e  # Exit on error
+trap 'handle_error $? $LINENO $BASH_LINENO "$BASH_COMMAND" $(printf "::%s" 
${FUNCNAME[@]:-})' ERR
+
+# Error handling function
+handle_error() {
+    local exit_code=$1
+    local line_no=$2
+    local bash_lineno=$3
+    local last_command=$4
+    local func_trace=$5
+
+    cat << "EOF"
+     _____ ____  ____   ___  ____
+    | ____|  _ \|  _ \ / _ \|  _ \
+    |  _| | |_) | |_) | | | | |_) |
+    | |___|  _ <|  _ <| |_| |  _ <
+    |_____|_| \_\_| \_\\___/|_| \_\
+
+EOF
+    echo "Error occurred in:"
+    echo "  Command: $last_command"
+    echo "  Line: $line_no"
+    echo "  Exit code: $exit_code"
+    if [ ! -z "$func_trace" ]; then
+        echo "  Function trace: $func_trace"
+    fi
+    exit $exit_code
+}
+
+# Function to detect color support
+setup_colors() {
+    # Only use colors if connected to a terminal
+    if [ -t 1 ]; then
+        # Check if NO_COLOR is set (https://no-color.org/)
+        if [ -z "${NO_COLOR+x}" ]; then
+            # Check if terminal supports colors
+            if [ -n "$TERM" ] && [ "$TERM" != "dumb" ]; then
+                # Check if tput is available
+                if command -v tput > /dev/null && tput setaf 1 >&/dev/null; 
then
+                    RED='\033[0;31m'
+                    GREEN='\033[0;32m'
+                    YELLOW='\033[1;33m'
+                    BLUE='\033[0;34m'
+                    MAGENTA='\033[0;35m'
+                    CYAN='\033[0;36m'
+                    GRAY='\033[0;90m'
+                    BOLD='\033[1m'
+                    NC='\033[0m' # No Color
+
+                    # Unicode symbols (only if terminal likely supports UTF-8)
+                    if [ "$TERM" != "linux" ] && [ -n "$LANG" ] && [ "$LANG" 
!= "C" ]; then
+                        CHECK_MARK="✔"
+                        CROSS_MARK="✘"
+                        ARROW="➜"
+                        WARNING="⚠"
+                        INFO="ℹ"
+                    else
+                        CHECK_MARK="(+)"
+                        CROSS_MARK="(x)"
+                        ARROW="(>)"
+                        WARNING="(!)"
+                        INFO="(i)"
+                    fi
+
+                    HAS_COLORS=1
+                fi
+            fi
+        fi
+    fi
+
+    # If colors are not supported or disabled, use plain text without escape 
sequences
+    if [ -z "${HAS_COLORS+x}" ]; then
+        RED=''
+        GREEN=''
+        YELLOW=''
+        BLUE=''
+        MAGENTA=''
+        CYAN=''
+        GRAY=''
+        BOLD=''
+        NC=''
+
+        # Use ASCII alternatives without escape sequences
+        CHECK_MARK="(+)"
+        CROSS_MARK="(x)"
+        ARROW="(>)"
+        WARNING="(!)"
+        INFO="(i)"
+
+        HAS_COLORS=0
+    fi
+}
+
+# Initialize colors early
+setup_colors
+
+# Function to print section headers
+print_section() {
+    local text="$1"
+    local text_length=${#text}
+    local total_width=80  # Standard terminal width
+    local padding_length=$(( (total_width - text_length - 4) / 2 ))  # -4 for 
the borders and spaces
+    local left_padding=""
+    local right_padding=""
+
+    # Create padding strings of spaces for the text line
+    for ((i=0; i<padding_length; i++)); do
+        left_padding+=" "
+        right_padding+=" "
+    done
+
+    # Adjust right padding for odd lengths
+    if [ $(( (total_width - text_length) % 2 )) -eq 1 ]; then
+        right_padding+=" "
+    fi
+
+    if [ "$HAS_COLORS" -eq 1 ]; then
+        echo -e 
"\n${BLUE}╔════════════════════════════════════════════════════════════════════════════╗${NC}"
+        echo -e 
"${BLUE}║${NC}${left_padding}${BOLD}${text}${NC}${right_padding}${BLUE}║${NC}"
+        echo -e 
"${BLUE}╚════════════════════════════════════════════════════════════════════════════╝${NC}"
+    else
+        echo -e 
"\n+------------------------------------------------------------------------------+"
+        echo -e "| ${left_padding}${text}${right_padding} |"
+        echo 
"+------------------------------------------------------------------------------+"
+    fi
+}
+
+# Function to print status messages
+print_status() {
+    local status=$1
+    local message=$2
+    
+    if [ "$HAS_COLORS" -eq 1 ]; then
+        case $status in
+            "success")
+                echo -e " ${GREEN}${CHECK_MARK}${NC} ${GREEN}${message}${NC}"
+                ;;
+            "error")
+                echo -e " ${RED}${CROSS_MARK}${NC} ${RED}${message}${NC}"
+                ;;
+            "warning")
+                echo -e " ${YELLOW}${WARNING}${NC} ${YELLOW}${message}${NC}"
+                ;;
+            "info")
+                echo -e " ${CYAN}${INFO}${NC} ${CYAN}${message}${NC}"
+                ;;
+            *)
+                echo -e " ${BLUE}${ARROW}${NC} ${message}"
+                ;;
+        esac
+    else
+        # No colors - use plain text without escape sequences
+        local symbol
+        case $status in
+            "success")
+                symbol="${CHECK_MARK}"
+                ;;
+            "error")
+                symbol="${CROSS_MARK}"
+                ;;
+            "warning")
+                symbol="${WARNING}"
+                ;;
+            "info")
+                symbol="${INFO}"
+                ;;
+            *)
+                symbol="${ARROW}"
+                ;;
+        esac
+        echo " ${symbol} ${message}"
+    fi
+}
+
+# Enhanced progress tracking
+print_progress() {
+    local current=$1
+    local total=$2
+    local message=$3
+    local percentage=$((current * 100 / total))
+
+    if [ "$HAS_COLORS" -eq 1 ]; then
+        local filled=$((percentage / 2))
+        local empty=$((50 - filled))
+
+        local progress="["
+        for ((i=0; i<filled; i++)); do progress+="█"; done
+        for ((i=0; i<empty; i++)); do progress+="░"; done
+        progress+="]"
+
+        echo -e "\r${CYAN}${progress}${NC} ${percentage}% 
${GRAY}${message}${NC}"
+    else
+        local filled=$((percentage / 4))
+        local empty=$((25 - filled))
+
+        local progress="["
+        for ((i=0; i<filled; i++)); do progress+="#"; done
+        for ((i=0; i<empty; i++)); do progress+="-"; done
+        progress+="]"
+
+        echo -e "\r${progress} ${percentage}% ${message}"
+    fi
+}
+
+# Function to prompt for continuation
+prompt_continue() {
+    local prompt_text="$1"
+    if [ -z "$prompt_text" ]; then
+        prompt_text="Continue?"
+    fi
+    
+    read -p "$prompt_text (y/N) " -n 1 -r
+    echo
+    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+        exit 1
+    fi
+}
+
+# Add the new section header
+print_section "Apache Unomi Build Script"
+
+# Default values
+SKIP_TESTS=false
+RUN_INTEGRATION_TESTS=false
+DEPLOY=false
+DEBUG=false
+USE_MAVEN_CACHE=true
+PURGE_MAVEN_CACHE=false
+MAVEN_DEBUG=false
+MAVEN_OFFLINE=false
+KARAF_DEBUG_PORT=5005
+KARAF_DEBUG_SUSPEND=n
+USE_OPENSEARCH=false
+NO_KARAF=false
+AUTO_START=""
+SINGLE_TEST=""
+IT_DEBUG=false
+IT_DEBUG_PORT=5006
+IT_DEBUG_SUSPEND=false
+SKIP_MIGRATION_TESTS=false
+
+# Enhanced usage function with color support
+usage() {
+    if [ "$HAS_COLORS" -eq 1 ]; then
+        echo -e "${CYAN}"
+        cat << "EOF"
+     _    _ _____ _      ____
+    | |  | |  ___| |    |  _ \
+    | |__| | |__ | |    | |_) |
+    |  __  |  __|| |    |  __/
+    | |  | | |___| |____| |
+    |_|  |_\_____|______|_|
+EOF
+        echo -e "${NC}"
+
+        echo -e "${BOLD}Usage:${NC} $0 [options]"
+        echo
+        echo -e "${BOLD}Options:${NC}"
+        echo -e "  ${CYAN}-h, --help${NC}                 Show this help 
message"
+        echo -e "  ${CYAN}-s, --skip-tests${NC}           Skip all tests"
+        echo -e "  ${CYAN}-i, --integration-tests${NC}    Run integration 
tests"
+        echo -e "  ${CYAN}-d, --deploy${NC}               Deploy after build"
+        echo -e "  ${CYAN}-X, --maven-debug${NC}         Enable Maven debug 
output"
+        echo -e "  ${CYAN}-o, --offline${NC}             Run Maven in offline 
mode"
+        echo -e "  ${CYAN}--debug${NC}                    Run Karaf in debug 
mode"
+        echo -e "  ${CYAN}--debug-port PORT${NC}          Set debug port 
(default: 5005)"
+        echo -e "  ${CYAN}--debug-suspend${NC}           Suspend JVM until 
debugger connects"
+        echo -e "  ${CYAN}--no-maven-cache${NC}           Disable Maven build 
cache"
+        echo -e "  ${CYAN}--purge-maven-cache${NC}        Purge local Maven 
cache before building"
+        echo -e "  ${CYAN}--karaf-home PATH${NC}          Set Karaf home 
directory for deployment"
+        echo -e "  ${CYAN}--use-opensearch${NC}          Use OpenSearch 
instead of ElasticSearch"
+        echo -e "  ${CYAN}--no-karaf${NC}               Build without starting 
Karaf"
+        echo -e "  ${CYAN}--auto-start ENGINE${NC}      Auto-start with 
specified engine"
+        echo -e "  ${CYAN}--single-test TEST${NC}         Run a single 
integration test"
+        echo -e "  ${CYAN}--it-debug${NC}                 Enable integration 
test debug mode"
+        echo -e "  ${CYAN}--it-debug-port PORT${NC}        Set integration 
test debug port"
+        echo -e "  ${CYAN}--it-debug-suspend${NC}        Suspend integration 
test until debugger connects"
+        echo -e "  ${CYAN}--skip-migration-tests${NC}    Skip 
migration-related tests"
+    else
+        cat << "EOF"
+     _    _ _____ _      ____
+    | |  | |  ___| |    |  _ \
+    | |__| | |__ | |    | |_) |
+    |  __  |  __|| |    |  __/
+    | |  | | |___| |____| |
+    |_|  |_\_____|______|_|
+EOF
+        echo
+        echo "Usage: $0 [options]"
+        echo
+        echo "Options:"
+        echo "  -h, --help                 Show this help message"
+        echo "  -s, --skip-tests           Skip all tests"
+        echo "  -i, --integration-tests    Run integration tests"
+        echo "  -d, --deploy               Deploy after build"
+        echo "  -X, --maven-debug         Enable Maven debug output"
+        echo "  -o, --offline             Run Maven in offline mode"
+        echo "  --debug                    Run Karaf in debug mode"
+        echo "  --debug-port PORT          Set debug port (default: 5005)"
+        echo "  --debug-suspend           Suspend JVM until debugger connects"
+        echo "  --no-maven-cache           Disable Maven build cache"
+        echo "  --purge-maven-cache        Purge local Maven cache before 
building"
+        echo "  --karaf-home PATH          Set Karaf home directory for 
deployment"
+        echo "  --use-opensearch          Use OpenSearch instead of 
ElasticSearch"
+        echo "  --no-karaf               Build without starting Karaf"
+        echo "  --auto-start ENGINE      Auto-start with specified engine"
+        echo "  --single-test TEST         Run a single integration test"
+        echo "  --it-debug                Enable integration test debug mode"
+        echo "  --it-debug-port PORT      Set integration test debug port"
+        echo "  --it-debug-suspend        Suspend integration test until 
debugger connects"
+        echo "  --skip-migration-tests    Skip migration-related tests"
+    fi
+
+    echo
+    echo "Examples:"
+    if [ "$HAS_COLORS" -eq 1 ]; then
+        echo -e "  ${GRAY}# Build with integration tests using OpenSearch${NC}"

Review Comment:
   I use the NC for the examples, you're right it's not easy to read but it did 
look cool :) 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to