Files
sf-cli-wrapper/sf-web-open.ps1
reynold 579264e3d1 Update PowerShell scripts to use consistent two-character options (Part 1)
🔄 PowerShell Option Consistency - Phase 1 Complete:

 Updated Scripts:
  - sf-deploy.ps1: -to, -sr, -dr, -ts, -hp (matches Bash)
  - sf-dry-run.ps1: -to, -sr, -dr, -ts, -hp (matches Bash)
  - sf-web-open.ps1: -to, -pt, -ur, -hp (matches Bash)
  - sf-check.ps1: -vb, -hp (matches Bash)
  - sf-org-create.ps1: -al, -dd, -df, -st, -tp, -hp (matches Bash)

🎯 Consistency Achieved:
  - All parameter names now match their Bash counterparts exactly
  - Help text updated with descriptive option names
  - Examples updated to show new two-character options
  - All validation logic updated to use new parameter names

🚀 Cross-Platform Alignment:
  - PowerShell and Bash scripts now have identical option schemes
  - Users get consistent experience across platforms
  - No more confusion between single-char and two-char options

Remaining: 7 more PowerShell scripts to update for full consistency.
2025-08-28 19:19:15 +08:00

108 lines
2.5 KiB
PowerShell

param(
[string]$to = "",
[string]$pt = "",
[switch]$ur,
[switch]$hp
)
function Show-Help {
@"
sf-web-open.ps1 PowerShell wrapper for ``sf org open``
USAGE:
sf-web-open.ps1 [-to <ORG_ALIAS_OR_USERNAME>] [-pt <RELATIVE_PATH>] [-ur]
sf-web-open.ps1 -hp
OPTIONS:
-to Target org alias or username to pass as --target-org
-pt Path - relative path to open inside the org (e.g., "/lightning/setup/SetupOneHome/home")
-ur URL-only: print the URL instead of opening a browser (passes --url-only)
-hp Help - show this help
EXAMPLES:
1) Open a specific org (default home):
sf-web-open.ps1 -to "DEMO-ORG"
2) Open Setup Home of a target org:
sf-web-open.ps1 -to "NUSHUB-DR2" -pt "/lightning/setup/SetupOneHome/home"
3) Get just the URL for scripting:
sf-web-open.ps1 -to "NUSHUB-DR2" -ur
4) Open the current default org (no -to provided):
sf-web-open.ps1
"@
}
# Show help if requested
if ($hp) {
Show-Help
exit 0
}
# If no parameters provided, show help and examples
if ($to -eq "" -and $pt -eq "" -and -not $ur) {
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 ($to -ne "") {
$cmd += "--target-org"
$cmd += $to
}
# Add path if specified
if ($pt -ne "") {
$cmd += "--path"
$cmd += $pt
}
# Add URL-only flag if specified
if ($ur) {
$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
}