Skip to content

Commit

Permalink
Merge pull request #44 from mikebattista/mikebattista/PSNativeCommand…
Browse files Browse the repository at this point in the history
…ArgumentPassing

Fixed regression caused by PowerShell 7.3 breaking change
  • Loading branch information
mikebattista authored Nov 16, 2022
2 parents 8686e1f + 42f5846 commit 2c8dc7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion WslInterop.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = '.\WslInterop.psm1'

# Version number of this module.
ModuleVersion = '0.4.0'
ModuleVersion = '0.4.1'

# Supported PSEditions
CompatiblePSEditions = 'Core'
Expand Down
20 changes: 18 additions & 2 deletions WslInterop.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,25 @@ function global:Import-WslCommand() {
`$distribution = ("-d `$(`$WslDefaultParameterValues."-d")", "")[`$WslDefaultParameterValues."-d" -eq `$null]
`$username = ("-u `$(`$WslDefaultParameterValues."-u")", "")[`$WslDefaultParameterValues."-u" -eq `$null]
`$environmentVariables = ((`$WslEnvironmentVariables.Keys | ForEach-Object { "`$_='`$(`$WslEnvironmentVariables."`$_")'" }), "")[`$WslEnvironmentVariables.Count -eq 0]
`$defaultArgs = (`$WslDefaultParameterValues."$_", "")[`$WslDefaultParameterValues.Disabled -eq `$true]
`$defaultArgs = (`$WslDefaultParameterValues."$_", "")[`$WslDefaultParameterValues."$_" -eq `$null -or `$WslDefaultParameterValues.Disabled -eq `$true]
if (`$defaultArgs -is [scriptblock]) { `$defaultArgs = . `$defaultArgs }
`$commandLine = "`$distribution `$username `$environmentVariables $_ `$defaultArgs `$args" -split ' '
`$commandLine = ""
if (`$distribution -ne "") {
`$commandLine += "`$distribution "
}
if (`$username -ne "") {
`$commandLine += "`$username "
}
if (`$environmentVariables -ne "") {
`$commandLine += "`$environmentVariables "
}
`$commandLine += "$_ "
if (`$defaultArgs -ne "") {
`$commandLine += "`$defaultArgs "
}
`$commandLine += "`$args"
`$commandLine = "`$commandLine".Trim() -split ' '
# Invoke the command.
if (`$input.MoveNext()) {
Expand Down

0 comments on commit 2c8dc7a

Please sign in to comment.