-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opt(decompress): Add [Array] and pipeline support to Expand-XXX
's params
#3534
base: develop
Are you sure you want to change the base?
Conversation
@niheaven Could you also look into this? {
"version": "5.4.6.0",
"url": "http://www.vieas.com/software/dl/Vieas5460_32.zip#/cosi",
"pre_install": "\"$dir\\$fname\" | Expand-7zipArchive; 'WRONG'",
"post_install": "\"$dir\\$fname\" | Expand-7zipArchive -DestinationPath $dir; 'OK'"
} When using pipeline, default DestinationPath is not resolved as |
OK.Nevermind. This come from PowerShell precedence of execution. Parameters are validated and binded before pipeline input processing. This could be solved with removing default from |
@Ash258 I've found it and fixed in this PR, it should be okay when this is merged. 😄 |
It "accept array path param" -Skip:$isUnix { | ||
$to = test_extract "Expand-InnoArchive" @($test) | ||
$to | Should -Exist | ||
"$to\empty" | Should -Exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incosistency. You are using Join-Path in #L74
Expand-7zipArchive $Path $DestinationPath -Removal | ||
return | ||
process { | ||
if (!$DestinationPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in process block?
# Remove original archive file | ||
Remove-Item $currentPath -Force | ||
} | ||
} | ||
} | ||
} | ||
|
||
function Expand-ZipArchive { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add synopsis to functions
@@ -39,12 +39,13 @@ function Expand-7zipArchive { | |||
[CmdletBinding()] | |||
param ( | |||
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch ($Overwrite) { | ||
"All" { $ArgList += "-aoa" } | ||
"Skip" { $ArgList += "-aos" } | ||
"Rename" { $ArgList += "-aou" } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use single quotes
} | ||
$currentDestinationPath = $currentDestinationPath.TrimEnd("\") | ||
if ($currentExtractDir) { | ||
$OriDestinationPath = $currentDestinationPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local variable
$OriDestinationPath = $currentDestinationPath | |
$oriDestinationPath = $currentDestinationPath |
"^[^{].*" { $ArgList += "-c{app}\$currentExtractDir" } | ||
"^{.*" { $ArgList += "-c$currentExtractDir" } | ||
Default { $ArgList += "-c{app}" } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- single quotes
- default is lowercased when switch is lowercased
$currentExtractDir = $null | ||
} | ||
if ($currentExtractDir) { | ||
$OriDestinationPath = $currentDestinationPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local varaible
# try to fall back to 7zip if path is too long | ||
if (Test-HelperInstalled -Helper 7zip) { | ||
Expand-7zipArchive $currentPath $currentDestinationPath -Removal | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you break whole foreach?
Now
Expand-xxx
functions accept [Array] params (Path
,DestinationPath
,ExtractDir
), and work for pipeline params (aa, bb, cc | Expand-xxx
or@(aa, bb, cc) | Expand-xxx
.No more
ForEach-Object { Expand-xxx $_ }
.Useful for install script in manifests.