feat: add environment variable expansion for arty deps
Adds support for environment variables like $COMFYUI_ROOT in the 'into' field of references when running 'arty deps'. Features:
- New expand_env_vars() function with nested variable expansion support
- Validates that no undefined variables remain after expansion
- Fails with clear error messages showing undefined variables
- Lists available environment variables from arty.yml in error output
- Expands variables from envs section before cloning repositories
Example usage in arty.yml:
```yaml
envs:
default:
COMFYUI_ROOT: /workspace/ComfyUI
references:
- url: https://github.com/ltdrdata/ComfyUI-Manager.git
into: $COMFYUI_ROOT/custom_nodes/ComfyUI-Manager
```
Expands to: /workspace/ComfyUI/custom_nodes/ComfyUI-Manager
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -72,6 +72,40 @@ log_step() {
|
|||||||
# ARTY.SH CORE FUNCTIONS - Repository Management
|
# ARTY.SH CORE FUNCTIONS - Repository Management
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
|
# Expand environment variables in a string with validation
|
||||||
|
# Supports nested expansion (e.g., $AI_ROOT/subdir where AI_ROOT contains another var)
|
||||||
|
# Fails if any undefined variables remain after expansion
|
||||||
|
expand_env_vars() {
|
||||||
|
local input="$1"
|
||||||
|
local max_iterations=10
|
||||||
|
local iteration=0
|
||||||
|
local expanded="$input"
|
||||||
|
|
||||||
|
# Keep expanding until no more variables or max iterations reached
|
||||||
|
while [[ "$expanded" =~ \$ ]] && [[ $iteration -lt $max_iterations ]]; do
|
||||||
|
# Use eval to expand variables
|
||||||
|
expanded=$(eval echo "$expanded" 2>/dev/null || echo "$expanded")
|
||||||
|
iteration=$((iteration+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check if any unexpanded variables remain
|
||||||
|
if [[ "$expanded" =~ \$[A-Za-z_][A-Za-z0-9_]* ]]; then
|
||||||
|
# Extract the undefined variable name for better error message
|
||||||
|
local undefined_var=$(echo "$expanded" | grep -o '\$[A-Za-z_][A-Za-z0-9_]*' | head -1)
|
||||||
|
log_error "Undefined environment variable in path: ${undefined_var}"
|
||||||
|
log_error " Original: $input"
|
||||||
|
log_error " Expanded: $expanded"
|
||||||
|
log_error ""
|
||||||
|
log_error "Available environment variables from arty.yml:"
|
||||||
|
if [[ -f "$ARTY_CONFIG_FILE" ]]; then
|
||||||
|
yq eval '.envs.default | keys | .[]' "$ARTY_CONFIG_FILE" 2>/dev/null | sed 's/^/ - /' || true
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$expanded"
|
||||||
|
}
|
||||||
|
|
||||||
# Load environment variables from arty.yml
|
# Load environment variables from arty.yml
|
||||||
load_env_vars() {
|
load_env_vars() {
|
||||||
local config_file="${1:-$ARTY_CONFIG_FILE}"
|
local config_file="${1:-$ARTY_CONFIG_FILE}"
|
||||||
@@ -376,9 +410,16 @@ install_lib() {
|
|||||||
# Determine installation directory
|
# Determine installation directory
|
||||||
local lib_dir
|
local lib_dir
|
||||||
if [[ -n "$custom_into" ]]; then
|
if [[ -n "$custom_into" ]]; then
|
||||||
|
# Expand environment variables in custom_into path
|
||||||
|
local expanded_into
|
||||||
|
if ! expanded_into=$(expand_env_vars "$custom_into"); then
|
||||||
|
log_error "Failed to expand environment variables in 'into' path for ${repo_url}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Custom directory relative to config file directory
|
# Custom directory relative to config file directory
|
||||||
local config_dir=$(dirname "$(realpath "${config_file}")")
|
local config_dir=$(dirname "$(realpath "${config_file}")")
|
||||||
lib_dir="$config_dir/$custom_into"
|
lib_dir="$config_dir/$expanded_into"
|
||||||
else
|
else
|
||||||
# Use global .arty/libs for libraries without custom 'into'
|
# Use global .arty/libs for libraries without custom 'into'
|
||||||
lib_dir="$ARTY_LIBS_DIR/$lib_name"
|
lib_dir="$ARTY_LIBS_DIR/$lib_name"
|
||||||
|
|||||||
Reference in New Issue
Block a user