Skip to content

Commit

Permalink
MSFT_PackageManagement: Support passing AdditionalParameters typed as…
Browse files Browse the repository at this point in the history
… switch or bool

Syntax:
AdditionalParameters = @{ '[switch]InstallUpdate' = 'True' }

Fixes OneGet#327.
  • Loading branch information
jberezanski committed Feb 24, 2021
1 parent c1826bb commit 6fad704
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,26 @@ function Add-AdditionalParameters
$AdditionalParameters
)

$rxTypePrefix = [regex]'^(?i)\[(?<type>[a-z]+)\]'
if ($AdditionalParameters)
{
foreach($instance in $AdditionalParameters)
{
Write-Verbose ('AdditionalParameter: {0}, AdditionalParameterValue: {1}' -f $instance.Key, $instance.Value)
$null = $ParametersDictionary.Add($instance.Key, $instance.Value)
$key = $instance.Key
$value = $instance.Value
$match = $rxTypePrefix.Match($key)
if ($match.Success)
{
if (@('switch', 'bool') -icontains $match.Groups['type'].Value)
{
Write-Verbose ('Parsing parameter ''{0}'' value ''{1}'' as bool and removing type prefix ''{2}''' -f $key, $value, $match.Value)
$key = $key.Substring($match.Length)
$value = [bool]::Parse($value)
}
}

$null = $ParametersDictionary.Add($key, $value)
}
}
}
Expand Down

0 comments on commit 6fad704

Please sign in to comment.