param( [string]$o = "", [string]$p = "", [switch]$U, [switch]$h ) function Show-Help { @" sf-web-open.ps1 — PowerShell wrapper for ``sf org open`` USAGE: sf-web-open.ps1 [-o ] [-p ] [-U] sf-web-open.ps1 -h OPTIONS: -o Org alias or username to pass as --target-org -p Relative path to open inside the org (e.g., "/lightning/setup/SetupOneHome/home") -U URL-only: print the URL instead of opening a browser (passes --url-only) -h Show this help EXAMPLES: 1) Open a specific org (default home): sf-web-open.ps1 -o "DEMO-ORG" 2) Open Setup Home of a target org: sf-web-open.ps1 -o "NUSHUB-DR2" -p "/lightning/setup/SetupOneHome/home" 3) Get just the URL for scripting: sf-web-open.ps1 -o "NUSHUB-DR2" -U 4) Open the current default org (no -o provided): sf-web-open.ps1 "@ } # Show help if requested if ($h) { Show-Help exit 0 } # If no parameters provided, show help and examples if ($o -eq "" -and $p -eq "" -and -not $U) { Show-Help exit 0 } # Silent environment check - verify SF CLI is available try { Get-Command sf -ErrorAction Stop | Out-Null } catch { Write-Host "❌ Salesforce CLI (sf) not found!" -ForegroundColor Red Write-Host "" Write-Host "Running environment check to help you get started..." Write-Host "" # Try to find and run sf-check.ps1 in the same directory as this script $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $sfCheckPath = Join-Path $scriptDir "sf-check.ps1" if (Test-Path $sfCheckPath) { & $sfCheckPath } elseif (Get-Command sf-check.ps1 -ErrorAction SilentlyContinue) { sf-check.ps1 } else { Write-Host "sf-check.ps1 not found. Please install the Salesforce CLI from:" Write-Host "https://developer.salesforce.com/tools/sfdxcli" } exit 1 } # Build the command array $cmd = @("sf", "org", "open") # Add target org if specified if ($o -ne "") { $cmd += "--target-org" $cmd += $o } # Add path if specified if ($p -ne "") { $cmd += "--path" $cmd += $p } # Add URL-only flag if specified if ($U) { $cmd += "--url-only" } # Display the command being executed Write-Host ">>> Running: $($cmd -join ' ')" -ForegroundColor Yellow # Execute the command try { & $cmd[0] $cmd[1..($cmd.Length-1)] exit $LASTEXITCODE } catch { Write-Error "Failed to execute sf command: $_" exit 1 }