feat(core): Merge-PackageControlSettings hash

- This function used to only accept a file, but can now accept a hash
 - This allows for easily configuring pre-release version of Sublime to
    auto-update
This commit is contained in:
Iristyle
2013-09-16 15:36:36 -04:00
parent c0b4b0e4c1
commit f649c48b3a

View File

@@ -120,6 +120,9 @@ function Install-SublimePackageControl
$packageUrl = 'https://sublime.wbond.net/prerelease/Package%20Control.sublime-package'
}
Get-ChocolateyWebFile -url $packageUrl -fileFullPath $packageControl
$settings = @{ 'install_prereleases' = $PreRelease }
Merge-PackageControlSettings -Settings $settings -Version $Version
}
3 {
@@ -132,12 +135,16 @@ function Install-SublimePackageControl
function Merge-PackageControlSettings
{
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = "File")]
param(
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $false, ParameterSetName = "File")]
[string]
$FilePath,
[Parameter(Mandatory = $false, ParameterSetName = "Hash")]
[Hashtable]
$Settings,
[Parameter(Mandatory = $false)]
[ValidateRange(2,3)]
[int]
@@ -156,7 +163,14 @@ function Merge-PackageControlSettings
$existing = ConvertFrom-Json $existingText
Write-Verbose "Existing settings: `n`n$existingText`n`n"
$new = ConvertFrom-Json ([IO.File]::ReadAllText($FilePath))
if ($PsCmdlet.ParameterSetName -eq 'File')
{
$new = ConvertFrom-Json ([IO.File]::ReadAllText($FilePath))
}
else
{
$new = $Settings
}
$simpleArrays = @('installed_packages', 'repositories', 'channels',
'auto_upgrade_ignore', 'git_update_command', 'hg_update_command',
@@ -177,7 +191,9 @@ function Merge-PackageControlSettings
% { Merge-JsonArrayOfSimpleMap -Name $_ -Destination $existing -Array $new.$_ }
$excluded = $simpleArrays + $maps + $arrayOfMaps
$new.PSObject.Properties |
if ($new -is [PSCustomObject]) { $props = $new.PSObject.Properties }
else { $props = $new.GetEnumerator() }
$props |
? { $excluded -inotcontains $_.Name } |
% {
Merge-JsonNamedValue -Name $_.Name -Destination $existing -Value $_.Value