Fix sf-org-info array handling for bash strict mode

🐛 Fixed Critical Issue:
  - Resolved 'unbound variable' error with cmd_args[@] in strict mode
  - Used  expansion for safe array handling
  - Now works correctly with 'set -euo pipefail'

 Verified Working:
  - sf-org-info -l: Lists all authenticated orgs
  - sf-org-info -o ORG: Shows specific org information
  - sf-org-info -o ORG -v: Shows detailed org limits and info
  - Default org fallback when no org specified

The script now works reliably with proper error handling and strict bash mode.
This commit is contained in:
reynold
2025-08-28 18:59:00 +08:00
parent 312727a905
commit e82de4ea12

View File

@@ -109,10 +109,10 @@ show_org_info() {
echo "======================================="
# Get basic org info
if sf org display "${cmd_args[@]}" --json >/dev/null 2>&1; then
if sf org display ${cmd_args[@]:+"${cmd_args[@]}"} --json >/dev/null 2>&1; then
echo
echo "📊 Basic Information:"
sf org display "${cmd_args[@]}" 2>/dev/null || {
sf org display ${cmd_args[@]:+"${cmd_args[@]}"} 2>/dev/null || {
echo "❌ Unable to retrieve org information"
return 1
}
@@ -127,8 +127,8 @@ show_org_info() {
echo
echo "📈 Org Limits:"
echo "-------------"
if sf org list limits "${cmd_args[@]}" >/dev/null 2>&1; then
sf org list limits "${cmd_args[@]}" 2>/dev/null | head -20 || echo "Unable to retrieve org limits"
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
@@ -136,8 +136,8 @@ show_org_info() {
echo
echo "⚙️ Org Shape (if available):"
echo "-----------------------------"
if sf org list shape "${cmd_args[@]}" >/dev/null 2>&1; then
sf org list shape "${cmd_args[@]}" 2>/dev/null || echo "No org shapes available"
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