Files
wild-cloud/bin/wild-config-set

80 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
set -e
set -o pipefail
# Usage function
usage() {
echo "Usage: wild-config-set <yaml_key_path> <value>"
echo ""
echo "Set a value in \$WC_HOME/config.yaml using a YAML key path."
echo ""
echo "Examples:"
echo " wild-config-set 'cluster.name' 'my-cluster' # Set cluster name"
echo " wild-config-set 'cloud.domain' 'example.com' # Set domain"
echo " wild-config-set 'cloud.dns.ip' '192.168.1.10' # Set DNS IP"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
exit 0
;;
-*)
echo "Unknown option $1"
usage
exit 1
;;
*)
if [ -z "${KEY_PATH}" ]; then
KEY_PATH="$1"
elif [ -z "${VALUE}" ]; then
VALUE="$1"
else
echo "Too many arguments"
usage
exit 1
fi
shift
;;
esac
done
if [ -z "${KEY_PATH}" ]; then
echo "Error: YAML key path is required"
usage
exit 1
fi
if [ -z "${VALUE}" ]; then
echo "Error: Value is required"
usage
exit 1
fi
# Initialize Wild Cloud environment
if [ -z "${WC_ROOT}" ]; then
print "WC_ROOT is not set."
exit 1
else
source "${WC_ROOT}/scripts/common.sh"
init_wild_env
fi
CONFIG_FILE="${WC_HOME}/config.yaml"
# Create config file if it doesn't exist
if [ ! -f "${CONFIG_FILE}" ]; then
echo "Creating new config file at ${CONFIG_FILE}"
echo "{}" > "${CONFIG_FILE}"
fi
# Use yq to set the value in the YAML file
yq eval ".${KEY_PATH} = \"${VALUE}\"" -i "${CONFIG_FILE}"
echo "Set ${KEY_PATH} = ${VALUE}"