fixed ps scripts
This commit is contained in:
130
sf-retrieve.ps1
130
sf-retrieve.ps1
@@ -8,35 +8,35 @@
|
||||
A user-friendly wrapper around 'sf project retrieve' commands that simplifies
|
||||
metadata retrieval from Salesforce orgs with intelligent defaults and validation.
|
||||
|
||||
.PARAMETER MetadataTypes
|
||||
.PARAMETER mt
|
||||
Comma-separated list of metadata types to retrieve (e.g., "ApexClass,CustomObject")
|
||||
|
||||
.PARAMETER Manifest
|
||||
.PARAMETER mf
|
||||
Path to package.xml or manifest file for retrieval
|
||||
|
||||
.PARAMETER Package
|
||||
.PARAMETER pk
|
||||
Package name for package-based retrieval
|
||||
|
||||
.PARAMETER OutputDir
|
||||
.PARAMETER od
|
||||
Output directory for retrieved metadata (default: current directory)
|
||||
|
||||
.PARAMETER o
|
||||
.PARAMETER to
|
||||
Target org username or alias (uses default if not specified)
|
||||
|
||||
.PARAMETER Wait
|
||||
.PARAMETER wt
|
||||
Wait time in minutes for the retrieve operation (default: 10)
|
||||
|
||||
.PARAMETER VerboseOutput
|
||||
.PARAMETER ve
|
||||
Enable verbose output
|
||||
|
||||
.PARAMETER Help
|
||||
.PARAMETER hp
|
||||
Show this help message
|
||||
|
||||
.EXAMPLE
|
||||
.\sf-retrieve.ps1 -MetadataTypes "ApexClass,CustomObject" -o myorg -OutputDir retrieved
|
||||
.\sf-retrieve.ps1 -Manifest "manifest/package.xml"
|
||||
.\sf-retrieve.ps1 -Package "MyPackage" -o "myorg"
|
||||
.\sf-retrieve.ps1 -MetadataTypes "Flow" -OutputDir "./retrieved" -Verbose
|
||||
.\sf-retrieve.ps1 -mt "ApexClass,CustomObject" -to myorg -od retrieved
|
||||
.\sf-retrieve.ps1 -mf "manifest/package.xml"
|
||||
.\sf-retrieve.ps1 -pk "MyPackage" -to "myorg"
|
||||
.\sf-retrieve.ps1 -mt "Flow" -od "./retrieved" -ve
|
||||
|
||||
.NOTES
|
||||
This script automatically checks for Salesforce CLI installation and runs
|
||||
@@ -44,42 +44,24 @@
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(ParameterSetName="Types")]
|
||||
[string]$MetadataTypes,
|
||||
|
||||
[Parameter(ParameterSetName="Manifest")]
|
||||
[string]$Manifest,
|
||||
|
||||
[Parameter(ParameterSetName="Package")]
|
||||
[string]$Package,
|
||||
|
||||
[Parameter(ParameterSetName="Types")]
|
||||
[Parameter(ParameterSetName="Manifest")]
|
||||
[Parameter(ParameterSetName="Package")]
|
||||
[string]$OutputDir,
|
||||
|
||||
[Parameter(ParameterSetName="Types")]
|
||||
[Parameter(ParameterSetName="Manifest")]
|
||||
[Parameter(ParameterSetName="Package")]
|
||||
[string]$o,
|
||||
|
||||
[Parameter(ParameterSetName="Types")]
|
||||
[Parameter(ParameterSetName="Manifest")]
|
||||
[Parameter(ParameterSetName="Package")]
|
||||
[int]$Wait = 10,
|
||||
|
||||
[Parameter(ParameterSetName="Types")]
|
||||
[Parameter(ParameterSetName="Manifest")]
|
||||
[Parameter(ParameterSetName="Package")]
|
||||
[switch]$VerboseOutput,
|
||||
|
||||
[Parameter(ParameterSetName="Help", Mandatory=$true)]
|
||||
[Alias("hp")]
|
||||
[switch]$Help
|
||||
[string]$mt,
|
||||
[string]$mf,
|
||||
[string]$pk,
|
||||
[string]$od,
|
||||
[string]$to,
|
||||
[int]$wt = 10,
|
||||
[switch]$ve,
|
||||
[switch]$hp
|
||||
)
|
||||
|
||||
# Show help if no parameters provided
|
||||
if (-not ($mt -or $mf -or $pk -or $hp)) {
|
||||
Get-Help $MyInvocation.MyCommand.Path -Detailed
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Show help if requested
|
||||
if ($Help) {
|
||||
if ($hp) {
|
||||
Get-Help $MyInvocation.MyCommand.Path -Detailed
|
||||
exit 0
|
||||
}
|
||||
@@ -120,27 +102,27 @@ if (-not (Test-SalesforceCLI)) {
|
||||
}
|
||||
|
||||
# Validate that exactly one retrieval method is specified
|
||||
$methodCount = @($MetadataTypes, $Manifest, $Package | Where-Object { $_ }).Count
|
||||
$methodCount = @($mt, $mf, $pk | Where-Object { $_ }).Count
|
||||
if ($methodCount -eq 0) {
|
||||
Write-Host "Error: Must specify one of: -MetadataTypes, -Manifest, or -Package" -ForegroundColor Red
|
||||
Write-Host "Error: Must specify one of: -mt, -mf, or -pk" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Write-Host "Usage examples:" -ForegroundColor Yellow
|
||||
Write-Host " .\sf-retrieve.ps1 -MetadataTypes `"ApexClass,CustomObject`"" -ForegroundColor Gray
|
||||
Write-Host " .\sf-retrieve.ps1 -Manifest `"manifest/package.xml`"" -ForegroundColor Gray
|
||||
Write-Host " .\sf-retrieve.ps1 -Package `"MyPackage`"" -ForegroundColor Gray
|
||||
Write-Host " .\sf-retrieve.ps1 -mt `"ApexClass,CustomObject`"" -ForegroundColor Gray
|
||||
Write-Host " .\sf-retrieve.ps1 -mf `"manifest/package.xml`"" -ForegroundColor Gray
|
||||
Write-Host " .\sf-retrieve.ps1 -pk `"MyPackage`"" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "Use -Help for detailed usage information." -ForegroundColor Yellow
|
||||
Write-Host "Use -hp for detailed usage information." -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($methodCount -gt 1) {
|
||||
Write-Host "Error: Can only specify one of: -MetadataTypes, -Manifest, or -Package" -ForegroundColor Red
|
||||
Write-Host "Error: Can only specify one of: -mt, -mf, or -pk" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Validate manifest file exists if specified
|
||||
if ($Manifest -and -not (Test-Path $Manifest)) {
|
||||
Write-Host "Error: Manifest file not found: $Manifest" -ForegroundColor Red
|
||||
if ($mf -and -not (Test-Path $mf)) {
|
||||
Write-Host "Error: Manifest file not found: $mf" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -148,43 +130,43 @@ if ($Manifest -and -not (Test-Path $Manifest)) {
|
||||
$sfArgs = @("project", "retrieve", "start")
|
||||
|
||||
# Add retrieval method
|
||||
if ($MetadataTypes) {
|
||||
if ($mt) {
|
||||
$sfArgs += "--metadata"
|
||||
$sfArgs += $MetadataTypes
|
||||
Write-Host "Retrieving metadata types: $MetadataTypes" -ForegroundColor Green
|
||||
} elseif ($Manifest) {
|
||||
$sfArgs += $mt
|
||||
Write-Host "Retrieving metadata types: $mt" -ForegroundColor Green
|
||||
} elseif ($mf) {
|
||||
$sfArgs += "--manifest"
|
||||
$sfArgs += $Manifest
|
||||
Write-Host "Retrieving from manifest: $Manifest" -ForegroundColor Green
|
||||
} elseif ($Package) {
|
||||
$sfArgs += $mf
|
||||
Write-Host "Retrieving from manifest: $mf" -ForegroundColor Green
|
||||
} elseif ($pk) {
|
||||
$sfArgs += "--package-name"
|
||||
$sfArgs += $Package
|
||||
Write-Host "Retrieving package: $Package" -ForegroundColor Green
|
||||
$sfArgs += $pk
|
||||
Write-Host "Retrieving package: $pk" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Add optional parameters
|
||||
if ($OutputDir) {
|
||||
if (-not (Test-Path $OutputDir)) {
|
||||
Write-Host "Creating output directory: $OutputDir" -ForegroundColor Yellow
|
||||
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
|
||||
if ($od) {
|
||||
if (-not (Test-Path $od)) {
|
||||
Write-Host "Creating output directory: $od" -ForegroundColor Yellow
|
||||
New-Item -ItemType Directory -Path $od -Force | Out-Null
|
||||
}
|
||||
$sfArgs += "--output-dir"
|
||||
$sfArgs += $OutputDir
|
||||
$sfArgs += $od
|
||||
}
|
||||
|
||||
if ($o) {
|
||||
if ($to) {
|
||||
$sfArgs += "--target-org"
|
||||
$sfArgs += $o
|
||||
Write-Host "Target org: $o" -ForegroundColor Cyan
|
||||
$sfArgs += $to
|
||||
Write-Host "Target org: $to" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
if ($Wait -ne 10) {
|
||||
if ($wt -ne 10) {
|
||||
$sfArgs += "--wait"
|
||||
$sfArgs += $Wait.ToString()
|
||||
$sfArgs += $wt.ToString()
|
||||
}
|
||||
|
||||
# Add verbose flag if requested
|
||||
if ($VerboseOutput) {
|
||||
if ($ve) {
|
||||
$sfArgs += "--verbose"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user