Extracts common library from wild scripts.
This commit is contained in:
@@ -3,98 +3,11 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# Get WC_ROOT (where this script and templates live)
|
||||
WC_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
export WC_ROOT
|
||||
# Source common utilities
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/wild-common.sh"
|
||||
|
||||
# =============================================================================
|
||||
# HELPER FUNCTIONS
|
||||
# =============================================================================
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Helper functions
|
||||
print_header() {
|
||||
echo -e "\n${BLUE}=== $1 ===${NC}\n"
|
||||
}
|
||||
|
||||
print_info() {
|
||||
echo -e "${BLUE}INFO:${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}WARNING:${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}SUCCESS:${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}ERROR:${NC} $1"
|
||||
}
|
||||
|
||||
# Function to prompt for input with default value
|
||||
prompt_with_default() {
|
||||
local prompt="$1"
|
||||
local default="$2"
|
||||
local current_value="$3"
|
||||
local result
|
||||
|
||||
if [ -n "${current_value}" ] && [ "${current_value}" != "null" ]; then
|
||||
printf "%s [current: %s]: " "${prompt}" "${current_value}" >&2
|
||||
read -r result
|
||||
if [ -z "${result}" ]; then
|
||||
result="${current_value}"
|
||||
fi
|
||||
elif [ -n "${default}" ]; then
|
||||
printf "%s [default: %s]: " "${prompt}" "${default}" >&2
|
||||
read -r result
|
||||
if [ -z "${result}" ]; then
|
||||
result="${default}"
|
||||
fi
|
||||
else
|
||||
printf "%s: " "${prompt}" >&2
|
||||
read -r result
|
||||
while [ -z "${result}" ]; do
|
||||
printf "This value is required. Please enter a value: " >&2
|
||||
read -r result
|
||||
done
|
||||
fi
|
||||
|
||||
echo "${result}"
|
||||
}
|
||||
|
||||
# Function to get current config value safely
|
||||
get_current_config() {
|
||||
local key="$1"
|
||||
if [ -f "${WC_HOME}/config.yaml" ]; then
|
||||
set +e
|
||||
result=$(wild-config "${key}" 2>/dev/null)
|
||||
set -e
|
||||
echo "${result}"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to get current secret value safely
|
||||
get_current_secret() {
|
||||
local key="$1"
|
||||
if [ -f "${WC_HOME}/secrets.yaml" ]; then
|
||||
set +e
|
||||
result=$(wild-secret "${key}" 2>/dev/null)
|
||||
set -e
|
||||
echo "${result}"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
# Initialize Wild-Cloud environment
|
||||
init_wild_env
|
||||
|
||||
UPDATE=false
|
||||
|
||||
|
Reference in New Issue
Block a user