From f649c48b3a2e26b9780e42884b71bb45ccfb2138 Mon Sep 17 00:00:00 2001 From: Iristyle Date: Mon, 16 Sep 2013 15:36:36 -0400 Subject: [PATCH] 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 --- core/SublimeHelpers.ps1 | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/core/SublimeHelpers.ps1 b/core/SublimeHelpers.ps1 index d66c284..6138b4b 100644 --- a/core/SublimeHelpers.ps1 +++ b/core/SublimeHelpers.ps1 @@ -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