#!/bin/bash

# Check if a variable name is provided
if [ $# -ne 1 ]; then
    echo "Usage: $0 <variable-name>"
    exit 1
fi

# The variable name to search for
variable_name="$1"

# Base directory to search in
base_dir="inventory/"

# Search YAML files and output the variable's value if found
find "$base_dir" -type f -name '*.yaml' | while read -r yaml_file; do
    value=$(yq eval ".${variable_name}" "$yaml_file" 2> /dev/null)
    if [ ! -z "$value" ] && [ "$value" != "null" ]; then
        echo "Found in $yaml_file: $value"
    fi
done
