Skip to content

Commit 0a918c2

Browse files
HeyItsGilbertclaudeCopilot
authored
style: format all PS1 source files with Invoke-Formatter (#182)
## Summary - Ran `Invoke-Formatter` (PSScriptAnalyzer) across all 62 source `.ps1` files - `Output\` directory excluded — it is auto-generated by `StageFiles` - No logic changes; whitespace and style only ## Test plan - [x] Run `.\build.ps1 StageFiles` to verify staging still works - [x] Run Pester tests to confirm no regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Gilbert Sanchez <me@gilbertsanchez.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent da16223 commit 0a918c2

62 files changed

Lines changed: 1247 additions & 1486 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Examples/Install-PSDepend.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# No PowerShellGallery? Run this to install PSDepend.
1+
# No PowerShellGallery? Run this to install PSDepend.
22
# Downloads nuget to your ~\ home directory
33
# Creates $Path (and full path to it)
44
# Downloads module to $Path\PSDepend
@@ -7,17 +7,17 @@
77
# Example: .\Install-PSDepend -Path C:\Modules (Installs to C:\Modules\PSDepend)
88
param( [string]$Path ) # Parent folder PSDepend is installed to. Defaults to Profile\WindowsPowerShell\Modules and creates dir if needed
99

10-
if(-not $Path) { $Path = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'WindowsPowerShell\Modules' }
10+
if (-not $Path) { $Path = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'WindowsPowerShell\Modules' }
1111

1212
# Bootstrap nuget if we don't have it
13-
if(-not ($NugetPath = (Get-Command 'nuget.exe' -ErrorAction SilentlyContinue).Path)) {
13+
if (-not ($NugetPath = (Get-Command 'nuget.exe' -ErrorAction SilentlyContinue).Path)) {
1414
$NugetPath = Join-Path $ENV:USERPROFILE nuget.exe
15-
if(-not (Test-Path $NugetPath)) { Invoke-WebRequest -uri 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $NugetPath }
15+
if (-not (Test-Path $NugetPath)) { Invoke-WebRequest -Uri 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $NugetPath }
1616
}
1717

1818
# Bootstrap PSDepend, re-use nuget.exe for the module
19-
if($path) { $null = New-Item $path -ItemType Directory -Force }
19+
if ($path) { $null = New-Item $path -ItemType Directory -Force }
2020
$NugetParams = 'install', 'PSDepend', '-Source', 'https://www.powershellgallery.com/api/v2/',
21-
'-ExcludeVersion', '-NonInteractive', '-OutputDirectory', $Path
21+
'-ExcludeVersion', '-NonInteractive', '-OutputDirectory', $Path
2222
& $NugetPath @NugetParams
2323
Move-Item -Path $NugetPath -Destination "$(Join-Path $Path PSDepend)\nuget.exe" -Force

PSDepend/PSDependScripts/Chocolatey.ps1

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ function Get-ChocoInstalledPackage {
8484
'--local-only'
8585
)
8686
$invokeExternalCommandSplat = @{
87-
Command = 'choco.exe'
87+
Command = 'choco.exe'
8888
Arguments = $chocoParams
89-
PassThru = $true
89+
PassThru = $true
9090
}
9191
$convertFromCsvSplat = @{
92-
Header = 'Name', 'Version'
92+
Header = 'Name', 'Version'
9393
Delimiter = "|"
9494
}
9595
Invoke-ExternalCommand @invokeExternalCommandSplat | ConvertFrom-Csv @convertFromCsvSplat
@@ -118,12 +118,12 @@ function Get-ChocoLatestPackage {
118118
}
119119

120120
$invokeExternalCommandSplat = @{
121-
Command = 'choco.exe'
121+
Command = 'choco.exe'
122122
Arguments = $chocoParams
123-
PassThru = $true
123+
PassThru = $true
124124
}
125125
$convertFromCsvSplat = @{
126-
Header = 'Name', 'Version'
126+
Header = 'Name', 'Version'
127127
Delimiter = "|"
128128
}
129129
Invoke-ExternalCommand @invokeExternalCommandSplat | ConvertFrom-Csv @convertFromCsvSplat
@@ -172,7 +172,7 @@ function Invoke-ChocoInstallPackage {
172172
}
173173

174174
$invokeExternalCommandSplat = @{
175-
Command = 'choco.exe'
175+
Command = 'choco.exe'
176176
Arguments = $chocoParams
177177
}
178178
Invoke-ExternalCommand @invokeExternalCommandSplat
@@ -209,7 +209,8 @@ if (-not (Get-Command -Name 'choco.exe' -ErrorAction SilentlyContinue)) {
209209
try {
210210
Invoke-WebRequest -UseBasicParsing -Uri $ChocoInstallScriptUrl -OutFile $scriptPath
211211
& $scriptPath
212-
} catch {
212+
}
213+
catch {
213214
throw "Unable to install Chocolatey from '$scriptUrl'."
214215
}
215216
}
@@ -239,14 +240,15 @@ Write-Verbose "Getting package [$Name] version, if it is installed."
239240
$existingVersion = (Get-ChocoInstalledPackage -Name $Name).Version
240241
if ($existingVersion) {
241242
Write-Verbose "Found package [$Name] installed with version [$existingVersion]."
242-
} else {
243+
}
244+
else {
243245
Write-Verbose "Package [$Name] not installed."
244246
}
245247

246248
# Version latest requested, and equal to current
247249
if ($Version -ne 'latest' -and $Version -eq $existingVersion) {
248250
Write-Verbose "You have the requested version [$Version] of [$Name]"
249-
if($PSDependAction -contains 'Test') {
251+
if ($PSDependAction -contains 'Test') {
250252
return $true
251253
}
252254

@@ -266,7 +268,8 @@ Write-Verbose "Getting latest package [$Name] version from source [$Source]."
266268
$repositoryVersion = (Get-ChocoLatestPackage @repoParams).Version
267269
if ($repositoryVersion) {
268270
Write-Verbose "Found package [$Name] version [$repositoryVersion] on source [$Source]."
269-
} else {
271+
}
272+
else {
270273
Write-Verbose "Package [$Name] not found on source [$Source]. Nothing more can be done."
271274
return # cannot continue
272275
}
@@ -277,7 +280,7 @@ if (
277280
([System.Version]$repositoryVersion -le [System.Version]$existingVersion)
278281
) {
279282
Write-Verbose "You have the latest version of [$Name], with installed version [$existingVersion] and Source version [$repositoryVersion]"
280-
if($PSDependAction -contains 'Test') {
283+
if ($PSDependAction -contains 'Test') {
281284
return $true
282285
}
283286

@@ -300,6 +303,7 @@ if ($PSDependAction -contains 'Install') {
300303
}
301304

302305
Invoke-ChocoInstallPackage @params
303-
} elseif ($PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
306+
}
307+
elseif ($PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
304308
return $false
305309
}

PSDepend/PSDependScripts/Command.ps1

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,18 @@ param (
4646

4747
Write-Verbose "Executing $($Dependency.count) commands"
4848

49-
foreach($Depend in $Dependency)
50-
{
51-
foreach($Command in $Depend.Source)
52-
{
49+
foreach ($Depend in $Dependency) {
50+
foreach ($Command in $Depend.Source) {
5351
Write-Verbose "Invoking command [$($Dependency.DependencyName)]:`n$Command"
5452
$ScriptBlock = [ScriptBlock]::Create($Command)
55-
Try
56-
{
53+
Try {
5754
. $ScriptBlock
5855
}
59-
Catch
60-
{
61-
if($FailOnError)
62-
{
56+
Catch {
57+
if ($FailOnError) {
6358
throw $_
6459
}
65-
else
66-
{
60+
else {
6761
Write-Error $_
6862
continue
6963
}

PSDepend/PSDependScripts/DotnetSdk.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ if ($PSDependAction -contains 'Install') {
8181
# If the InstallDir is not set, set it to the 'global' path
8282
if (!$InstallDir) {
8383
$InstallTo = $globalDotnetSdkLocation
84-
} else {
84+
}
85+
else {
8586
$InstallTo = $InstallDir
8687
}
8788
Install-Dotnet -Channel $Channel -Version $Version -InstallDir $InstallTo
@@ -93,13 +94,15 @@ if ($PSDependAction -contains 'Import') {
9394
# If the InstallDir was specified and the .NET Core SDK exists in it, add it to the path
9495
if ($InstallDir -and (Test-Dotnet -Version $Version -InstallDir $InstallDir)) {
9596
$env:PATH = "$InstallDir$([IO.Path]::PathSeparator)$env:PATH"
96-
} else {
97+
}
98+
else {
9799
# Test if it's in the path already and if it's not check if it's in the 'global' location
98100
$dotnetInPath = Get-Command 'dotnet' -ErrorAction SilentlyContinue
99101
if (!$dotnetInPath) {
100102
if (!(Test-Dotnet -Version $Version -InstallDir $globalDotnetSdkLocation)) {
101103
throw ".NET SDK cannot be located. Try installing using PSDepend."
102-
} else {
104+
}
105+
else {
103106
$env:PATH = "$globalDotnetSdkLocation$([IO.Path]::PathSeparator)$env:PATH"
104107
}
105108
}

PSDepend/PSDependScripts/FileDownload.ps1

Lines changed: 68 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -46,116 +46,98 @@ param(
4646
)
4747

4848
function Parse-URLForFile {
49-
[cmdletbinding()]
50-
param($URL)
49+
[cmdletbinding()]
50+
param($URL)
5151
# This will need work. Assume leaf is file. If CGI exists in leaf, assume it is after the file
5252
$FileName = $URL.split('/')[-1]
53-
if($FileName -match '\?')
54-
{
53+
if ($FileName -match '\?') {
5554
$FileName.split('?')[0]
5655
}
57-
else
58-
{
56+
else {
5957
$FileName
6058
}
6159
Write-Verbose "Parsed file name [$FileName] from `$URL"
6260
}
6361

6462
# Extract data from Dependency
65-
$DependencyName = $Dependency.DependencyName
66-
$Name = $Dependency.Name
67-
$Target = $Dependency.Target
68-
$Source = $Dependency.Source
69-
70-
# Pick the URL
71-
if($Source)
72-
{
73-
$URL = $Source
74-
}
75-
else
76-
{
77-
$URL = $DependencyName
78-
}
79-
Write-Verbose "Using URL: $URL"
63+
$DependencyName = $Dependency.DependencyName
64+
$Name = $Dependency.Name
65+
$Target = $Dependency.Target
66+
$Source = $Dependency.Source
67+
68+
# Pick the URL
69+
if ($Source) {
70+
$URL = $Source
71+
}
72+
else {
73+
$URL = $DependencyName
74+
}
75+
Write-Verbose "Using URL: $URL"
8076

8177
# Act on target path....
82-
$ToInstall = $False # Anti pattern
83-
$TargetParent = Split-Path $Target -Parent
84-
$PathToAdd = $Target
85-
if( (Test-Path $TargetParent) -and -not (Test-Path $Target))
86-
{
87-
# They gave us a full path, don't parse the file name, use this!
88-
$Path = $Target
89-
$ToInstall = $True
90-
Write-Verbose "Found parent [$TargetParent], not target [$Target], assuming this is target file path"
78+
$ToInstall = $False # Anti pattern
79+
$TargetParent = Split-Path $Target -Parent
80+
$PathToAdd = $Target
81+
if ( (Test-Path $TargetParent) -and -not (Test-Path $Target)) {
82+
# They gave us a full path, don't parse the file name, use this!
83+
$Path = $Target
84+
$ToInstall = $True
85+
Write-Verbose "Found parent [$TargetParent], not target [$Target], assuming this is target file path"
86+
}
87+
elseif (Test-Path $Target -PathType Leaf) {
88+
# File exists. We should download to temp spot, compare hashes, take action as appropriate.
89+
# For now, skip the file.
90+
Write-Verbose "Skipping existing file [$Target]"
91+
if ($PSDependAction -contains 'Test') {
92+
return $True
9193
}
92-
elseif(Test-Path $Target -PathType Leaf)
93-
{
94-
# File exists. We should download to temp spot, compare hashes, take action as appropriate.
95-
# For now, skip the file.
96-
Write-Verbose "Skipping existing file [$Target]"
97-
if($PSDependAction -contains 'Test')
98-
{
99-
return $True
100-
}
101-
$PathToAdd = Split-Path $Target -Parent
94+
$PathToAdd = Split-Path $Target -Parent
95+
}
96+
elseif (-not (Test-Path $Target)) {
97+
# They gave us something that doesn't look like a new container for a new or existing file. Wat?
98+
Write-Error "Could not find target path [$Target]"
99+
if ($PSDependAction -contains 'Test') {
100+
return $False
102101
}
103-
elseif(-not (Test-Path $Target))
104-
{
105-
# They gave us something that doesn't look like a new container for a new or existing file. Wat?
106-
Write-Error "Could not find target path [$Target]"
107-
if($PSDependAction -contains 'Test')
108-
{
109-
return $False
110-
}
102+
}
103+
else {
104+
Write-Verbose "[$Target] is a container, creating path to file"
105+
# We have a target container, now find the name
106+
If ($Name) {
107+
# explicit name
108+
$FileName = $Name
111109
}
112-
else
113-
{
114-
Write-Verbose "[$Target] is a container, creating path to file"
115-
# We have a target container, now find the name
116-
If($Name)
117-
{
118-
# explicit name
119-
$FileName = $Name
120-
}
121-
else
122-
{
123-
$FileName = Parse-URLForFile -URL $URL
124-
}
125-
$Path = Join-Path $Target $FileName
110+
else {
111+
$FileName = Parse-URLForFile -URL $URL
112+
}
113+
$Path = Join-Path $Target $FileName
126114

127-
if(Test-Path $Path -PathType Leaf)
128-
{
129-
Write-Verbose "Skipping existing file [$Path]"
130-
if($PSDependAction -contains 'Test')
131-
{
132-
return $True
133-
}
134-
}
135-
else
136-
{
137-
$ToInstall = $True
115+
if (Test-Path $Path -PathType Leaf) {
116+
Write-Verbose "Skipping existing file [$Path]"
117+
if ($PSDependAction -contains 'Test') {
118+
return $True
138119
}
139120
}
140-
Write-Verbose "Using [$Path] as `$Target"
141-
142-
#No dependency found, return false if we're testing alone...
143-
if( $PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1)
144-
{
145-
return $False
121+
else {
122+
$ToInstall = $True
146123
}
147-
Write-Verbose "Downloading [$URL] to [$Path]"
124+
}
125+
Write-Verbose "Using [$Path] as `$Target"
126+
127+
#No dependency found, return false if we're testing alone...
128+
if ( $PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
129+
return $False
130+
}
131+
Write-Verbose "Downloading [$URL] to [$Path]"
148132

149-
if($PSDependAction -contains 'Install' -and $ToInstall)
150-
{
133+
if ($PSDependAction -contains 'Install' -and $ToInstall) {
151134
# Future considerations:
152-
# Should we check for existing? And if we find it, still download file, and compare sha256 hash, replace if it does not match?
153-
# We should consider credentials at some point, but PSD1 does not lend itself to securely storing passwords
135+
# Should we check for existing? And if we find it, still download file, and compare sha256 hash, replace if it does not match?
136+
# We should consider credentials at some point, but PSD1 does not lend itself to securely storing passwords
154137
Get-WebFile -URL $URL -Path $Path
155138
}
156139

157-
if($Dependency.AddToPath)
158-
{
140+
if ($Dependency.AddToPath) {
159141
Write-Verbose "Setting PATH to`n$($PathToAdd, $env:PATH -join ';' | Out-String)"
160142
Add-ToItemCollection -Reference Env:\Path -Item $PathToAdd
161143
}

0 commit comments

Comments
 (0)