Skip to content

Commit aeb9069

Browse files
Address PR review feedback from Copilot
- Replace Join-String (PS 7+ only) with -join operator for PS 5.1 compat - Add known switch parameter list to prevent consuming positional args after switches like -Force (e.g. 'Install-Module -Force Pester') - Fix README to document dot-sourcing instead of removed module manifest Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 0c951b2 commit aeb9069

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

tool/migration/ConvertTo-PSResourceGet.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function Find-PSGetCommand {
184184
)
185185

186186
if ($parseErrors.Count -gt 0) {
187-
Write-Warning "Parse errors in '$Path': $($parseErrors | ForEach-Object { $_.Message } | Join-String -Separator '; ')"
187+
Write-Warning "Parse errors in '$Path': $(($parseErrors | ForEach-Object { $_.Message }) -join '; ')"
188188
}
189189

190190
$commandAsts = $ast.FindAll({
@@ -263,10 +263,19 @@ function Convert-PSGetCommand {
263263
$paramName = $element.ParameterName
264264
$paramValue = $null
265265

266+
# Known switch parameters that never take a value argument
267+
$switchParams = @(
268+
'Force', 'AllowClobber', 'AllowPrerelease', 'AllVersions',
269+
'SkipPublisherCheck', 'Reinstall', 'Prerelease',
270+
'AcceptLicense', 'NoClobber', 'NoPathUpdate',
271+
'PassThru', 'WhatIf', 'Confirm', 'TrustRepository'
272+
)
273+
266274
if ($null -ne $element.Argument) {
267275
$paramValue = $element.Argument.Extent.Text
268276
}
269-
elseif (($i + 1) -lt $elements.Count -and
277+
elseif ($switchParams -notcontains $paramName -and
278+
($i + 1) -lt $elements.Count -and
270279
$elements[$i + 1] -isnot [System.Management.Automation.Language.CommandParameterAst]) {
271280
$i++
272281
$paramValue = $elements[$i].Extent.Text

tool/migration/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ cmdlets to their [PSResourceGet](https://github.com/PowerShell/PSResourceGet) eq
7474

7575
- `Find-RoleCapability` — No PSResourceGet equivalent. Generates a warning.
7676

77-
## Using as a Module
77+
## Using as a Script Library
7878

7979
```powershell
80-
Import-Module .\tool\migration\PSGetMigration.psd1
80+
# Dot-source the script to load all functions
81+
. .\tool\migration\ConvertTo-PSResourceGet.ps1
8182
8283
# Scan a single file
8384
$results = ConvertTo-PSResourceGetScript -Path .\deploy.ps1

tool/migration/Tests/PSGetMigration.Tests.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ Get-InstalledModule
211211
$result.ConvertedText | Should -Not -Match '-Force'
212212
}
213213

214+
It 'Does not consume positional argument after a switch parameter' {
215+
$result = Invoke-ConvertFromScript -Script 'Install-Module -Force Pester'
216+
$result.ConvertedText | Should -Match 'Install-PSResource'
217+
$result.ConvertedText | Should -Match 'Pester'
218+
$result.ConvertedText | Should -Match '-Reinstall'
219+
}
220+
214221
It 'Returns NoEquivalent for Find-RoleCapability' {
215222
$result = Invoke-ConvertFromScript -Script 'Find-RoleCapability -Name MyRole'
216223
$result.Status | Should -Be 'NoEquivalent'

0 commit comments

Comments
 (0)