#!/bin/bash
# install-and-verify-wp-cli.sh
# Installs wp-cli if not present, verifies installation, and prints version.

set -e

# Check if wp is already installed and in PATH
if command -v wp &> /dev/null; then
  echo "wp-cli is already installed."
else
  echo "wp-cli not found. Installing..."
  curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  php wp-cli.phar --info
  chmod +x wp-cli.phar
  sudo mv wp-cli.phar /usr/local/bin/wp
fi

# Verify installation
if command -v wp &> /dev/null; then
  echo "wp-cli installation verified."
  wp --version
else
  echo "wp-cli installation failed."
  exit 1
fi