Files
sf-cli-wrapper/sf-org-info
reynold 1ae8df8561 Enforce strict two-character option scheme across all wrapper scripts
- Removed long options from input parsing in all bash scripts
- Updated all help texts to show only two-character options
- Fixed error messages to reference short options only
- All scripts now reject long options like --help, --verbose, --target-org
- Maintained internal use of long sf CLI commands (e.g., --target-org passed to sf)
- Updated README.md documentation to reflect two-character scheme only
- Scripts affected: sf-retrieve, sf-test-run, sf-data-import, sf-data-export
- PowerShell scripts already used correct two-character parameter scheme
- All wrapper scripts now have consistent user interface

This ensures strict consistency in the two-character option scheme
while maintaining backward compatibility for the sf CLI commands themselves.
2025-08-28 22:07:34 +08:00

231 lines
5.3 KiB
Bash
Executable File

#!/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 <ORG_ALIAS>] [-lm] [-ve] [-ls] [-hp]
OPTIONS:
-to Target org alias or username (if not provided, uses default org)
-lm Show detailed org limits information
-ve 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 org limits:
sf-org-info -to DEMO-ORG -lm
4) Show detailed org information:
sf-org-info -to DEMO-ORG -ve
5) 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
SHOW_LIMITS=false
# Show help if no arguments provided (consistent with PowerShell version)
if [[ $# -eq 0 ]]; then
show_help
exit 0
fi
# Parse arguments manually for two-character options
while [[ $# -gt 0 ]]; do
case $1 in
-to)
if [[ -n "${2:-}" && ! "$2" =~ ^- ]]; then
ORG="$2"
shift 2
else
echo "Error: -to requires a target org argument" >&2
show_help
exit 1
fi
;;
-lm)
SHOW_LIMITS=true
shift
;;
-ve)
VERBOSE=true
shift
;;
-ls)
LIST_ORGS=true
shift
;;
-hp)
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
# Show limits if requested
if [[ "$SHOW_LIMITS" == "true" ]]; then
echo
echo "📈 Organization Limits:"
echo "======================="
cmd_args=()
if [[ -n "$ORG" ]]; then
cmd_args+=(--target-org "$ORG")
fi
if sf org list limits ${cmd_args[@]:+"${cmd_args[@]}"} 2>/dev/null; then
echo
else
echo "❌ Unable to retrieve org limits"
echo "Make sure you're authenticated and the org exists."
fi
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 " - Show limits: sf-org-info${ORG:+ -to \"$ORG\"} -lm"
echo " - Detailed info: sf-org-info${ORG:+ -to \"$ORG\"} -ve"