#!/usr/bin/env bash set -euo pipefail show_help() { cat <<'EOF' sf-org-info — wrapper for quick org information display USAGE: sf-org-info [-to ] [-vb] [-ls] [-hp] OPTIONS: -to Target org alias or username (if not provided, uses default org) -vb Verbose output (show detailed information) -ls List all authenticated orgs -hp Show this help EXAMPLES: 1) Show default org info: sf-org-info 2) Show specific org info: sf-org-info -to DEMO-ORG 3) Show detailed org information: sf-org-info -to DEMO-ORG -vb 4) List all authenticated orgs: sf-org-info -ls DISPLAYED INFORMATION: - Org name and ID - Username and user info - Instance URL and login URL - Org type and edition - API version and features - Limits and usage (verbose mode) - Connected app info (verbose mode) Notes: - If no org is specified, uses the default org - Verbose mode shows limits, features, and additional details - List mode shows all orgs you're authenticated to EOF } # Default values ORG="" VERBOSE=false LIST_ORGS=false # Parse arguments manually for two-character options while [[ $# -gt 0 ]]; do case $1 in -to|--target-org) if [[ -n "${2:-}" && ! "$2" =~ ^- ]]; then ORG="$2" shift 2 else echo "Error: -to requires a target org argument" >&2 show_help exit 1 fi ;; -vb|--verbose) VERBOSE=true shift ;; -ls|--list) LIST_ORGS=true shift ;; -hp|--help) show_help exit 0 ;; -*) echo "Unknown option: $1" >&2 echo show_help exit 1 ;; *) echo "Unexpected argument: $1" >&2 echo show_help exit 1 ;; esac done # Silent environment check if ! command -v sf >/dev/null 2>&1; then echo "❌ Salesforce CLI (sf) not found!" echo echo "Running environment check to help you get started..." echo SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [[ -x "$SCRIPT_DIR/sf-check" ]]; then "$SCRIPT_DIR/sf-check" elif command -v sf-check >/dev/null 2>&1; then sf-check else echo "sf-check not found. Please install the Salesforce CLI from:" echo "https://developer.salesforce.com/tools/sfdxcli" fi exit 1 fi # Function to display org list show_org_list() { echo "📋 Authenticated Organizations:" echo "==============================" if sf org list --json >/dev/null 2>&1; then sf org list 2>/dev/null || { echo "No authenticated orgs found." echo "Run 'sf org login web' to authenticate to an org." return 1 } else echo "❌ Unable to list orgs" return 1 fi } # Function to display org information show_org_info() { local target_org="$1" local cmd_args=() if [[ -n "$target_org" ]]; then cmd_args+=(--target-org "$target_org") echo "🏢 Organization Information: $target_org" else echo "🏢 Default Organization Information:" fi echo "=======================================" # Get basic org info if sf org display ${cmd_args[@]:+"${cmd_args[@]}"} --json >/dev/null 2>&1; then echo echo "📊 Basic Information:" sf org display ${cmd_args[@]:+"${cmd_args[@]}"} 2>/dev/null || { echo "❌ Unable to retrieve org information" return 1 } else echo "❌ Unable to retrieve org information" echo "Make sure you're authenticated and the org exists." return 1 fi # Show verbose information if requested if [[ "$VERBOSE" == "true" ]]; then echo echo "📈 Org Limits:" echo "-------------" if sf org list limits ${cmd_args[@]:+"${cmd_args[@]}"} >/dev/null 2>&1; then sf org list limits ${cmd_args[@]:+"${cmd_args[@]}"} 2>/dev/null | head -20 || echo "Unable to retrieve org limits" else echo "Unable to retrieve org limits" fi echo echo "⚙️ Org Shape (if available):" echo "-----------------------------" if sf org list shape ${cmd_args[@]:+"${cmd_args[@]}"} >/dev/null 2>&1; then sf org list shape ${cmd_args[@]:+"${cmd_args[@]}"} 2>/dev/null || echo "No org shapes available" else echo "No org shapes available" fi fi } # Handle list orgs option if [[ "$LIST_ORGS" == "true" ]]; then show_org_list exit $? fi # Show org information if ! show_org_info "$ORG"; then exit 1 fi echo echo "✅ Org information displayed successfully!" # Show helpful commands echo echo "💡 Helpful commands:" echo " - Open this org: sf org open${ORG:+ --target-org \"$ORG\"}" echo " - List all orgs: sf-org-info -ls" echo " - Detailed info: sf-org-info${ORG:+ -to \"$ORG\"} -vb"