Skip to content

Commit

Permalink
fix(config): Fix set_config bugs (ScoopInstaller#3681)
Browse files Browse the repository at this point in the history
Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
  • Loading branch information
jantari and niheaven authored Feb 10, 2022
1 parent b2a27f4 commit ef2bfeb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- **autoupdate:** Allow checksum file that contains whitespaces ([#4619](https://github.com/ScoopInstaller/Scoop/issues/4619))
- **autoupdate:** Rename $response to $res ([#4706](https://github.com/ScoopInstaller/Scoop/issues/4706))
- **config:** Allow scoop config use Unicode characters ([#4631](https://github.com/ScoopInstaller/Scoop/issues/4631))
- **config:** Fix `set_config` bugs ([#3681](https://github.com/ScoopInstaller/Scoop/issues/3681))
- **current:** Remove 'current' while it's not a junction ([#4687](https://github.com/ScoopInstaller/Scoop/issues/4687))
- **depends:** Prevent error on no URL ([#4595](https://github.com/ScoopInstaller/Scoop/issues/4595))
- **depends:** Check if extractor is available ([#4042](https://github.com/ScoopInstaller/Scoop/issues/4042))
Expand Down
32 changes: 19 additions & 13 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,33 @@ function get_config($name, $default) {
return $scoopConfig.$name
}

function set_config($name, $value) {
if($null -eq $scoopConfig -or $scoopConfig.Count -eq 0) {
function set_config {
Param (
[ValidateNotNullOrEmpty()]
$name,
$value
)

if ($null -eq $scoopConfig -or $scoopConfig.Count -eq 0) {
ensure (Split-Path -Path $configFile) | Out-Null
$scoopConfig = New-Object PSObject
$scoopConfig = New-Object -TypeName PSObject
}

if ($value -eq [bool]::TrueString -or $value -eq [bool]::FalseString) {
$value = [System.Convert]::ToBoolean($value)
}

if ($null -eq $scoopConfig.$name) {
$scoopConfig | Add-Member -MemberType NoteProperty -Name $name -Value $value
} else {
if($value -eq [bool]::TrueString -or $value -eq [bool]::FalseString) {
$value = [System.Convert]::ToBoolean($value)
}
if($null -eq $scoopConfig.$name) {
$scoopConfig | Add-Member -MemberType NoteProperty -Name $name -Value $value
} else {
$scoopConfig.$name = $value
}
$scoopConfig.$name = $value
}

if($null -eq $value) {
if ($null -eq $value) {
$scoopConfig.PSObject.Properties.Remove($name)
}

ConvertTo-Json $scoopConfig | Set-Content $configFile -Encoding Default
ConvertTo-Json $scoopConfig | Set-Content -Path $configFile -Encoding Default
return $scoopConfig
}

Expand Down

0 comments on commit ef2bfeb

Please sign in to comment.