diff --git a/README.md b/README.md index 6d03d29..3287b7a 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,11 @@ Unregister-PackageSource privateRepo -Provider ChocolateyGet ChocolateyGet integrates with Choco.exe to manage and store source information ## Pass in choco arguments -If you need to pass in some of choco arguments to the Find, Install, Get and Uninstall-Package cmdlets, you can use AdditionalArguments PowerShell property. +If you need to pass in additional package installation options, you can use either the dedicated package parameter and argument properties or the combined AdditionalArguments property. + +```powershell +Install-Package sysinternals -Provider ChocolateyGet -AcceptLicense -AdditionalArguments '--paramsglobal' -PackageParameters '/InstallDir:c:\windows\temp\sysinternals /QuickLaunchShortcut:false' -InstallArguments 'MaintenanceService=false' -Verbose +``` ```powershell Install-Package sysinternals -Provider ChocolateyGet -AcceptLicense -AdditionalArguments '--paramsglobal --params "/InstallDir:c:\windows\temp\sysinternals /QuickLaunchShortcut:false" -y --installargs MaintenanceService=false' -Verbose diff --git a/src/ChocolateyGet.psm1 b/src/ChocolateyGet.psm1 index 1cc908d..acb883d 100644 --- a/src/ChocolateyGet.psm1 +++ b/src/ChocolateyGet.psm1 @@ -6,6 +6,8 @@ $script:AcceptLicense = "AcceptLicense" $script:AdditionalArguments = "AdditionalArguments" $script:AllVersions = "AllVersions" $script:Force = "Force" +$script:InstallArguments = "InstallArguments" +$script:PackageParameters = "PackageParameters" $script:PackageSource = "Chocolatey" # Utility variables diff --git a/src/public/BaseFunctions.ps1 b/src/public/BaseFunctions.ps1 index 109ef1e..e9385ad 100644 --- a/src/public/BaseFunctions.ps1 +++ b/src/public/BaseFunctions.ps1 @@ -27,6 +27,8 @@ function Get-DynamicOptions { Install { Write-Output -InputObject (New-DynamicOption -Category $category -Name $script:AdditionalArguments -ExpectedType String -IsRequired $false) Write-Output -InputObject (New-DynamicOption -Category $category -Name $script:AcceptLicense -ExpectedType Switch -IsRequired $false) + Write-Output -InputObject (New-DynamicOption -Category $category -Name $script:PackageParameters -ExpectedType String -IsRequired $false) + Write-Output -InputObject (New-DynamicOption -Category $category -Name $script:InstallArguments -ExpectedType String -IsRequired $false) } } } diff --git a/src/public/Install-Package.ps1 b/src/public/Install-Package.ps1 index ff7343b..2c1a5cd 100644 --- a/src/public/Install-Package.ps1 +++ b/src/public/Install-Package.ps1 @@ -6,11 +6,7 @@ function Install-Package { [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string] - $FastPackageReference, - - [Parameter()] - [string] - $AdditionalArgs = ($request.Options[$script:AdditionalArguments]) + $FastPackageReference ) Write-Debug -Message ($LocalizedData.ProviderDebugMessage -f ('Install-Package')) @@ -38,10 +34,13 @@ function Install-Package { Version = $Matches.version Source = $Matches.source Force = $request.Options.ContainsKey($script:Force) + Parameters = $request.Options[$script:PackageParameters] + InstallArguments = $request.Options[$script:InstallArguments] } # Split on the first hyphen of each option/switch - [regex]::Split($AdditionalArgs,'(?:^|\s)-') | ForEach-Object { + # Overrides values passed through explicit package parameter/argument options + [regex]::Split($request.Options[$script:AdditionalArguments],'(?:^|\s)-') | ForEach-Object { Write-Debug "AdditionalArgs: $_" # Check each option/switch against known patterns that we can pass to Foil switch -Regex ($_) { diff --git a/test/ChocolateyGet.Unit.Tests.ps1 b/test/ChocolateyGet.Unit.Tests.ps1 index 50679af..6d0967a 100644 --- a/test/ChocolateyGet.Unit.Tests.ps1 +++ b/test/ChocolateyGet.Unit.Tests.ps1 @@ -82,9 +82,38 @@ Describe 'DSC-compliant package installation and uninstallation' { Uninstall-Package -Provider $ChocolateyGet -Name $package -AdditionalArguments $params | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty } } + Context 'with package parameters passed explicitly' { + BeforeAll { + $package = 'kitty' + $installDir = Join-Path -Path $env:ChocolateyInstall -ChildPath (Join-Path -Path 'lib' -ChildPath $package) + $kittyIniPath = Join-Path -Path $installDir -ChildPath (Join-Path -Path 'tools' -ChildPath 'kitty.ini') + $packageParams = "/Portable" + $wrappedParams = "--params ""/Dummy""" + Remove-Item -Force -Recurse -Path $installDir -ErrorAction SilentlyContinue + } + It 'silently installs the latest version of a package with explicit parameters' { + Install-Package -Force -Provider $ChocolateyGet -Name $package -PackageParameters $packageParams | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty + } + It 'correctly passed explicit parameters to the package' { + $kittyIniPath | Should -Exist + $kittyIniPath | Should -FileContentMatch 'savemode=dir' + } + It 'silently uninstalls the locally installed package just installed' { + Uninstall-Package -Provider $ChocolateyGet -Name $package | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty + } + It 'silently installs the latest version of a package with explicit and wrapped parameters' { + Install-Package -Force -Provider $ChocolateyGet -Name $package -PackageParameters $packageParams -AdditionalArguments $wrappedParams | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty + } + It 'correctly passed wrapped parameters to the package' { + $kittyIniPath | Should -Not -Exist + } + It 'silently uninstalls the locally installed package just installed again' { + Uninstall-Package -Provider $ChocolateyGet -Name $package | Where-Object {$_.Name -contains $package} | Should -Not -BeNullOrEmpty + } + } } -Describe 'pipline-based package installation and uninstallation' { +Describe 'pipeline-based package installation and uninstallation' { Context 'without additional arguments' { BeforeAll { $package = 'cpu-z'