From 08ecdd16a8aa999d4c567f417b0fc20b8af26a78 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Sun, 21 Aug 2022 19:51:31 +0800 Subject: [PATCH] fix(config): Change config option to snake_case in file and SCREAMING_CASE in code (#5116) --- CHANGELOG.md | 4 ++ bin/install.ps1 | 2 +- lib/core.ps1 | 73 ++++++++++++++++++++++++------------ lib/decompress.ps1 | 6 +-- lib/depends.ps1 | 4 +- lib/install.ps1 | 16 ++++---- lib/manifest.ps1 | 2 +- lib/unix.ps1 | 6 +-- lib/versions.ps1 | 2 +- libexec/scoop-cat.ps1 | 2 +- libexec/scoop-checkup.ps1 | 4 +- libexec/scoop-config.ps1 | 36 +++++++++++++----- libexec/scoop-export.ps1 | 2 +- libexec/scoop-hold.ps1 | 4 +- libexec/scoop-unhold.ps1 | 4 +- libexec/scoop-update.ps1 | 8 ++-- libexec/scoop-virustotal.ps1 | 2 +- test/Import-File-Tests.ps1 | 2 +- test/Scoop-Depends.Tests.ps1 | 10 ++--- 19 files changed, 118 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb89b2984..34888675d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - **scoop-update:** Stash uncommitted changes before update ([#5091](https://github.com/ScoopInstaller/Scoop/issues/5091)) - **install:** Show the running process ([#5102](https://github.com/ScoopInstaller/Scoop/issues/5102)) +### Bug Fixes + +- **config:** Change config option to snake_case in file and SCREAMING_CASE in code ([#5116](https://github.com/ScoopInstaller/Scoop/issues/5116)) + ## [v0.2.4](https://github.com/ScoopInstaller/Scoop/compare/v0.2.3...v0.2.4) - 2022-08-08 ### Features diff --git a/bin/install.ps1 b/bin/install.ps1 index 46cc0c21cc..c9c8a2e43f 100644 --- a/bin/install.ps1 +++ b/bin/install.ps1 @@ -70,7 +70,7 @@ Remove-Item "$dir\_tmp", $zipfile -Recurse -Force ensure_robocopy_in_path -set_config lastUpdate ([System.DateTime]::Now.ToString('o')) | Out-Null +set_config LAST_UPDATE ([System.DateTime]::Now.ToString('o')) | Out-Null success 'Scoop was installed successfully!' Write-Output "Type 'scoop help' for instructions." diff --git a/lib/core.ps1 b/lib/core.ps1 index 9277725e27..6b8a7ee633 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -59,6 +59,7 @@ function load_cfg($file) { } function get_config($name, $default) { + $name = $name.ToLowerInvariant() if($null -eq $scoopConfig.$name -and $null -ne $default) { return $default } @@ -72,6 +73,8 @@ function set_config { $value ) + $name = $name.ToLowerInvariant() + if ($null -eq $scoopConfig -or $scoopConfig.Count -eq 0) { ensure (Split-Path -Path $configFile) | Out-Null $scoopConfig = New-Object -TypeName PSObject @@ -98,7 +101,7 @@ function set_config { function setup_proxy() { # note: '@' and ':' in password must be escaped, e.g. 'p@ssword' -> p\@ssword' - $proxy = get_config 'proxy' + $proxy = get_config PROXY if(!$proxy) { return } @@ -126,7 +129,7 @@ function setup_proxy() { } function git_cmd { - $proxy = get_config 'proxy' + $proxy = get_config PROXY $cmd = "git $($args | ForEach-Object { "$_ " })" if ($proxy -and $proxy -ne 'none') { $cmd = "SET HTTPS_PROXY=$proxy&&SET HTTP_PROXY=$proxy&&$cmd" @@ -153,7 +156,7 @@ function error($msg) { write-host "ERROR $msg" -f darkred } function warn($msg) { write-host "WARN $msg" -f darkyellow } function info($msg) { write-host "INFO $msg" -f darkgray } function debug($obj) { - if((get_config 'debug' $false) -ine 'true' -and $env:SCOOP_DEBUG -ine 'true') { + if ((get_config DEBUG $false) -ine 'true' -and $env:SCOOP_DEBUG -ine 'true') { return } @@ -210,7 +213,7 @@ function appdir($app, $global) { "$(appsdir $global)\$app" } function versiondir($app, $version, $global) { "$(appdir $app $global)\$version" } function currentdir($app, $global) { - if (get_config NO_JUNCTIONS) { + if (get_config NO_JUNCTION) { $version = Select-CurrentVersion -App $app -Global:$global } else { $version = 'current' @@ -246,7 +249,7 @@ function installed_apps($global) { function failed($app, $global) { $app = ($app -split '/|\\')[-1] $appPath = appdir $app $global - $hasCurrent = (get_config NO_JUNCTIONS) -or (Test-Path "$appPath\current") + $hasCurrent = (get_config NO_JUNCTION) -or (Test-Path "$appPath\current") return (Test-Path $appPath) -and !($hasCurrent -and (installed $app $global)) } @@ -394,7 +397,7 @@ function app_status($app, $global) { $status.outdated = $false if ($status.version -and $status.latest_version) { - if (get_config 'force_update' $false) { + if (get_config FORCE_UPDATE $false) { $status.outdated = ((Compare-Version -ReferenceVersion $status.version -DifferenceVersion $status.latest_version) -ne 0) } else { $status.outdated = ((Compare-Version -ReferenceVersion $status.version -DifferenceVersion $status.latest_version) -gt 0) @@ -830,7 +833,7 @@ function shim($path, $global, $name, $arg) { function get_shim_path() { $shim_path = "$(versiondir 'scoop' 'current')\supporting\shims\kiennq\shim.exe" - $shim_version = get_config 'shim' 'default' + $shim_version = get_config SHIM 'default' switch ($shim_version) { '71' { $shim_path = "$(versiondir 'scoop' 'current')\supporting\shims\71\shim.exe"; Break } 'scoopcs' { $shim_path = "$(versiondir 'scoop' 'current')\supporting\shimexe\bin\shim.exe"; Break } @@ -999,17 +1002,17 @@ function show_app($app, $bucket, $version) { function is_scoop_outdated() { $now = [System.DateTime]::Now try { - $expireHour = (New-TimeSpan (get_config lastUpdate) $now).TotalHours + $expireHour = (New-TimeSpan (get_config LAST_UPDATE) $now).TotalHours return ($expireHour -ge 3) } catch { # If not System.DateTime - set_config lastUpdate ($now.ToString('o')) | Out-Null + set_config LAST_UPDATE ($now.ToString('o')) | Out-Null return $true } } function Test-ScoopCoreOnHold() { - $hold_update_until = get_config hold_update_until + $hold_update_until = get_config HOLD_UPDATE_UNTIL if ($null -eq $hold_update_until) { return $false } @@ -1027,7 +1030,7 @@ function Test-ScoopCoreOnHold() { error 'If you want to disable self-update of Scoop Core for a moment,' error "use 'scoop hold scoop' or 'scoop config hold_update_until /'." } - set_config hold_update_until $null | Out-Null + set_config HOLD_UPDATE_UNTIL $null | Out-Null return $false } @@ -1096,7 +1099,7 @@ function get_hash([String] $multihash) { } function Get-GitHubToken { - return $env:SCOOP_GH_TOKEN, (get_config 'gh_token') | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1 + return $env:SCOOP_GH_TOKEN, (get_config GH_TOKEN) | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1 } function handle_special_urls($url) @@ -1196,31 +1199,53 @@ function Out-UTF8File { # for all communication with api.github.com Optimize-SecurityProtocol -# Scoop config file migration +# Load Scoop config $configHome = $env:XDG_CONFIG_HOME, "$env:USERPROFILE\.config" | Select-Object -First 1 $configFile = "$configHome\scoop\config.json" -if ((Test-Path "$env:USERPROFILE\.scoop") -and !(Test-Path $configFile)) { - New-Item -ItemType Directory (Split-Path -Path $configFile) -ErrorAction Ignore | Out-Null - Move-Item "$env:USERPROFILE\.scoop" $configFile - write-host "WARN Scoop configuration has been migrated from '~/.scoop'" -f darkyellow - write-host "WARN to '$configFile'" -f darkyellow -} - -# Load Scoop config $scoopConfig = load_cfg $configFile +# NOTE Scoop config file migration. Remove this after 2023/6/30 +if ($scoopConfig) { + $newConfigNames = @{ + 'lastUpdate' = 'last_update' + 'SCOOP_REPO' = 'scoop_repo' + 'SCOOP_BRANCH' = 'scoop_branch' + '7ZIPEXTRACT_USE_EXTERNAL' = 'use_external_7zip' + 'MSIEXTRACT_USE_LESSMSI' = 'use_lessmsi' + 'NO_JUNCTIONS' = 'no_junction' + 'manifest_review' = 'show_manifest' + 'rootPath' = 'root_path' + 'globalPath' = 'global_path' + 'cachePath' = 'cache_path' + } + $newConfigNames.GetEnumerator() | ForEach-Object { + if ($null -ne $scoopConfig.$($_.Key)) { + $value = $scoopConfig.$($_.Key) + $scoopConfig.PSObject.Properties.Remove($_.Key) + $scoopConfig | Add-Member -MemberType NoteProperty -Name $_.Value -Value $value + if ($_.Key -eq 'lastUpdate') { + $scoopConfigChg = $true + } + } + } + if ($scoopConfigChg) { # Only save config file if there was a change + ConvertTo-Json $scoopConfig | Out-UTF8File -FilePath $configFile + } +} +# END NOTE + # Scoop root directory -$scoopdir = $env:SCOOP, (get_config 'rootPath'), "$env:USERPROFILE\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1 +$scoopdir = $env:SCOOP, (get_config ROOT_PATH), "$env:USERPROFILE\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1 # Scoop global apps directory -$globaldir = $env:SCOOP_GLOBAL, (get_config 'globalPath'), "$env:ProgramData\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -first 1 +$globaldir = $env:SCOOP_GLOBAL, (get_config GLOBAL_PATH), "$env:ProgramData\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1 # Scoop cache directory # Note: Setting the SCOOP_CACHE environment variable to use a shared directory # is experimental and untested. There may be concurrency issues when # multiple users write and access cached files at the same time. # Use at your own risk. -$cachedir = $env:SCOOP_CACHE, (get_config 'cachePath'), "$scoopdir\cache" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -first 1 +$cachedir = $env:SCOOP_CACHE, (get_config CACHE_PATH), "$scoopdir\cache" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1 # Setup proxy globally setup_proxy diff --git a/lib/decompress.ps1 b/lib/decompress.ps1 index 3c4e2cd08e..b56402b1d5 100644 --- a/lib/decompress.ps1 +++ b/lib/decompress.ps1 @@ -18,11 +18,11 @@ function Expand-7zipArchive { [Switch] $Removal ) - if ((get_config 7ZIPEXTRACT_USE_EXTERNAL)) { + if ((get_config USE_EXTERNAL_7ZIP)) { try { $7zPath = (Get-Command '7z' -CommandType Application -ErrorAction Stop | Select-Object -First 1).Source } catch [System.Management.Automation.CommandNotFoundException] { - abort "`nCannot find external 7-Zip (7z.exe) while '7ZIPEXTRACT_USE_EXTERNAL' is 'true'!`nRun 'scoop config 7ZIPEXTRACT_USE_EXTERNAL false' or install 7-Zip manually and try again." + abort "`nCannot find external 7-Zip (7z.exe) while 'use_external_7zip' is 'true'!`nRun 'scoop config use_external_7zip false' or install 7-Zip manually and try again." } } else { $7zPath = Get-HelperPath -Helper 7zip @@ -146,7 +146,7 @@ function Expand-MsiArchive { $OriDestinationPath = $DestinationPath $DestinationPath = "$DestinationPath\_tmp" } - if ((get_config MSIEXTRACT_USE_LESSMSI)) { + if ((get_config USE_LESSMSI)) { $MsiPath = Get-HelperPath -Helper Lessmsi $ArgList = @('x', $Path, "$DestinationPath\") } else { diff --git a/lib/depends.ps1 b/lib/depends.ps1 index bd2b26fb39..9c8d29042d 100644 --- a/lib/depends.ps1 +++ b/lib/depends.ps1 @@ -106,10 +106,10 @@ function Get-InstallationHelper { $installer = arch_specific 'installer' $Manifest $Architecture $post_install = arch_specific 'post_install' $Manifest $Architecture $script = $pre_install + $installer.script + $post_install - if (((Test-7zipRequirement -Uri $url) -or ($script -like '*Expand-7zipArchive *')) -and !(get_config 7ZIPEXTRACT_USE_EXTERNAL)) { + if (((Test-7zipRequirement -Uri $url) -or ($script -like '*Expand-7zipArchive *')) -and !(get_config USE_EXTERNAL_7ZIP)) { $helper += '7zip' } - if (((Test-LessmsiRequirement -Uri $url) -or ($script -like '*Expand-MsiArchive *')) -and (get_config MSIEXTRACT_USE_LESSMSI)) { + if (((Test-LessmsiRequirement -Uri $url) -or ($script -like '*Expand-MsiArchive *')) -and (get_config USE_LESSMSI)) { $helper += 'lessmsi' } if ($Manifest.innosetup -or ($script -like '*Expand-InnoArchive *')) { diff --git a/lib/install.ps1 b/lib/install.ps1 index 85524cba74..f6f159781d 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -30,9 +30,9 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru return } - if ((get_config 'manifest_review' $false) -and ($MyInvocation.ScriptName -notlike '*scoop-update*')) { + if ((get_config SHOW_MANIFEST $false) -and ($MyInvocation.ScriptName -notlike '*scoop-update*')) { Write-Host "Manifest: $app.json" - $style = get_config cat_style + $style = get_config CAT_STYLE if ($style) { $manifest | ConvertToPrettyJson | bat --no-paging --style $style --language json } else { @@ -214,7 +214,7 @@ function dl_with_cache_aria2($app, $version, $manifest, $architecture, $dir, $co $options += "--header='Cookie: $(cookie_header $cookies)'" } - $proxy = get_config 'proxy' + $proxy = get_config PROXY if ($proxy -ne 'none') { if ([Net.Webrequest]::DefaultWebProxy.Address) { $options += "--all-proxy='$([Net.Webrequest]::DefaultWebProxy.Address.Authority)'" @@ -371,7 +371,7 @@ function dl($url, $to, $cookies, $progress) { $wreq.Headers.Add('Cookie', (cookie_header $cookies)) } - get_config 'private_hosts' | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object { + get_config PRIVATE_HOSTS | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object { (ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object { $wreq.Headers[$_.Key] = $_.Value } @@ -588,7 +588,7 @@ function dl_urls($app, $version, $manifest, $bucket, $architecture, $dir, $use_c $extract_fn = 'Expand-InnoArchive' } elseif($fname -match '\.zip$') { # Use 7zip when available (more fast) - if (((get_config 7ZIPEXTRACT_USE_EXTERNAL) -and (Test-CommandAvailable 7z)) -or (Test-HelperInstalled -Helper 7zip)) { + if (((get_config USE_EXTERNAL_7ZIP) -and (Test-CommandAvailable 7z)) -or (Test-HelperInstalled -Helper 7zip)) { $extract_fn = 'Expand-7zipArchive' } else { $extract_fn = 'Expand-ZipArchive' @@ -909,7 +909,7 @@ function rm_shims($app, $manifest, $global, $arch) { # Returns the 'current' junction directory if in use, otherwise # the version directory. function link_current($versiondir) { - if (get_config NO_JUNCTIONS) { return $versiondir.ToString() } + if (get_config NO_JUNCTION) { return $versiondir.ToString() } $currentdir = "$(Split-Path $versiondir)\current" @@ -936,7 +936,7 @@ function link_current($versiondir) { # Returns the 'current' junction directory (if it exists), # otherwise the normal version directory. function unlink_current($versiondir) { - if (get_config NO_JUNCTIONS) { return $versiondir.ToString() } + if (get_config NO_JUNCTION) { return $versiondir.ToString() } $currentdir = "$(Split-Path $versiondir)\current" if (Test-Path $currentdir) { @@ -1234,7 +1234,7 @@ function test_running_process($app, $global) { $running_processes = Get-Process | Where-Object { $_.Path -like "$processdir\*" } | Out-String if ($running_processes) { - if (get_config 'ignore_running_processes') { + if (get_config IGNORE_RUNNING_PROCESSES) { warn "The following instances of `"$app`" are still running. Scoop is configured to ignore this condition." Write-Host $running_processes return $false diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 4a226f7c0a..274f288ec2 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -103,7 +103,7 @@ function install_info($app, $version, $global) { } function default_architecture { - $arch = get_config 'default_architecture' + $arch = get_config DEFAULT_ARCHITECTURE $system = if ([Environment]::Is64BitOperatingSystem) { '64bit' } else { '32bit' } if ($null -eq $arch) { $arch = $system diff --git a/lib/unix.ps1 b/lib/unix.ps1 index a57617dfae..b25d2e8c9c 100644 --- a/lib/unix.ps1 +++ b/lib/unix.ps1 @@ -10,9 +10,9 @@ if(!(is_unix)) { } # core.ps1 -$scoopdir = $env:SCOOP, (get_config 'rootPath'), (Join-Path $env:HOME "scoop") | Select-Object -first 1 -$globaldir = $env:SCOOP_GLOBAL, (get_config 'globalPath'), "/usr/local/scoop" | Select-Object -first 1 -$cachedir = $env:SCOOP_CACHE, (get_config 'cachePath'), (Join-Path $scoopdir "cache") | Select-Object -first 1 +$scoopdir = $env:SCOOP, (get_config ROOT_PATH), (Join-Path $env:HOME 'scoop') | Select-Object -First 1 +$globaldir = $env:SCOOP_GLOBAL, (get_config 'GLOBAL_PATH'), '/usr/local/scoop' | Select-Object -First 1 +$cachedir = $env:SCOOP_CACHE, (get_config 'CACHE_PATH'), (Join-Path $scoopdir 'cache') | Select-Object -First 1 # core.ps1 function ensure($dir) { diff --git a/lib/versions.ps1 b/lib/versions.ps1 index 5cf21a66f4..60530ec193 100644 --- a/lib/versions.ps1 +++ b/lib/versions.ps1 @@ -50,7 +50,7 @@ function Select-CurrentVersion { # 'manifest.ps1' ) process { $currentPath = "$(appdir $AppName $Global)\current" - if (!(get_config NO_JUNCTIONS)) { + if (!(get_config NO_JUNCTION)) { $currentVersion = (parse_json "$currentPath\manifest.json").version if ($currentVersion -eq 'nightly') { $currentVersion = (Get-Item $currentPath).Target | Split-Path -Leaf diff --git a/libexec/scoop-cat.ps1 b/libexec/scoop-cat.ps1 index ea59d1c73c..0e420bb046 100644 --- a/libexec/scoop-cat.ps1 +++ b/libexec/scoop-cat.ps1 @@ -11,7 +11,7 @@ if (!$app) { error ' missing'; my_usage; exit 1 } $null, $manifest, $bucket, $url = Get-Manifest $app if ($manifest) { - $style = get_config cat_style + $style = get_config CAT_STYLE if ($style) { $manifest | ConvertToPrettyJson | bat --no-paging --style $style --language json } else { diff --git a/libexec/scoop-checkup.ps1 b/libexec/scoop-checkup.ps1 index 1b3c329940..3c6c5f4f50 100644 --- a/libexec/scoop-checkup.ps1 +++ b/libexec/scoop-checkup.ps1 @@ -35,13 +35,13 @@ if (!(Test-HelperInstalled -Helper Dark)) { $globaldir = New-Object System.IO.DriveInfo($globaldir) if ($globaldir.DriveFormat -ne 'NTFS') { - error "Scoop requires an NTFS volume to work! Please point `$env:SCOOP_GLOBAL or 'globalPath' variable in '~/.config/scoop/config.json' to another Drive." + error "Scoop requires an NTFS volume to work! Please point `$env:SCOOP_GLOBAL or 'global_path' variable in '~/.config/scoop/config.json' to another Drive." $issues++ } $scoopdir = New-Object System.IO.DriveInfo($scoopdir) if ($scoopdir.DriveFormat -ne 'NTFS') { - error "Scoop requires an NTFS volume to work! Please point `$env:SCOOP or 'rootPath' variable in '~/.config/scoop/config.json' to another Drive." + error "Scoop requires an NTFS volume to work! Please point `$env:SCOOP or 'root_path' variable in '~/.config/scoop/config.json' to another Drive." $issues++ } diff --git a/libexec/scoop-config.ps1 b/libexec/scoop-config.ps1 index a686222470..6af46fc50a 100644 --- a/libexec/scoop-config.ps1 +++ b/libexec/scoop-config.ps1 @@ -21,20 +21,20 @@ # Settings # -------- # -# 7ZIPEXTRACT_USE_EXTERNAL: $true|$false +# use_external_7zip: $true|$false # External 7zip (from path) will be used for archives extraction. # -# MSIEXTRACT_USE_LESSMSI: $true|$false +# use_lessmsi: $true|$false # Prefer lessmsi utility over native msiexec. # -# NO_JUNCTIONS: $true|$false +# no_junction: $true|$false # The 'current' version alias will not be used. Shims and shortcuts will point to specific version instead. # -# SCOOP_REPO: http://github.com/ScoopInstaller/Scoop +# scoop_repo: http://github.com/ScoopInstaller/Scoop # Git repository containining scoop source code. # This configuration is useful for custom forks. # -# SCOOP_BRANCH: master|develop +# scoop_branch: master|develop # Allow to use different branch than master. # Could be used for testing specific functionalities before released into all users. # If you want to receive updates earlier to test new functionalities use develop (see: 'https://github.com/ScoopInstaller/Scoop/issues/2939') @@ -64,20 +64,20 @@ # show_update_log: $true|$false # Do not show changed commits on 'scoop update' # -# manifest_review: $true|$false +# show_manifest: $true|$false # Displays the manifest of every app that's about to # be installed, then asks user if they wish to proceed. # # shim: kiennq|scoopcs|71 # Choose scoop shim build. # -# rootPath: $Env:UserProfile\scoop +# root_path: $Env:UserProfile\scoop # Path to Scoop root directory. # -# globalPath: $Env:ProgramData\scoop +# global_path: $Env:ProgramData\scoop # Path to Scoop root directory for global apps. # -# cachePath: +# cache_path: # For downloads, defaults to 'cache' folder under Scoop root directory. # # gh_token: @@ -147,12 +147,30 @@ if (!$name) { } elseif ($name -like '--help') { my_usage } elseif ($name -like 'rm') { + # NOTE Scoop config file migration. Remove this after 2023/6/30 + if ($value -notin 'SCOOP_REPO', 'SCOOP_BRANCH' -and $value -in $newConfigNames.Keys) { + warn ('Config option "{0}" is deprecated, please use "{1}" instead next time.' -f $value, $newConfigNames.$value) + $value = $newConfigNames.$value + } + # END NOTE set_config $value $null | Out-Null Write-Host "'$value' has been removed" } elseif ($null -ne $value) { + # NOTE Scoop config file migration. Remove this after 2023/6/30 + if ($name -notin 'SCOOP_REPO', 'SCOOP_BRANCH' -and $name -in $newConfigNames.Keys) { + warn ('Config option "{0}" is deprecated, please use "{1}" instead next time.' -f $name, $newConfigNames.$name) + $name = $newConfigNames.$name + } + # END NOTE set_config $name $value | Out-Null Write-Host "'$name' has been set to '$value'" } else { + # NOTE Scoop config file migration. Remove this after 2023/6/30 + if ($name -notin 'SCOOP_REPO', 'SCOOP_BRANCH' -and $name -in $newConfigNames.Keys) { + warn ('Config option "{0}" is deprecated, please use "{1}" instead next time.' -f $name, $newConfigNames.$name) + $name = $newConfigNames.$name + } + # END NOTE $value = get_config $name if($null -eq $value) { Write-Host "'$name' is not set" diff --git a/libexec/scoop-export.ps1 b/libexec/scoop-export.ps1 index 5975e7eb7a..8eff8db0c5 100644 --- a/libexec/scoop-export.ps1 +++ b/libexec/scoop-export.ps1 @@ -10,7 +10,7 @@ $export = @{} if ($args[0] -eq '-c' -or $args[0] -eq '--config') { $export.config = $scoopConfig # Remove machine-specific properties - foreach ($prop in 'lastUpdate', 'rootPath', 'globalPath', 'cachePath', 'alias') { + foreach ($prop in 'last_update', 'root_path', 'global_path', 'cache_path', 'alias') { $export.config.PSObject.Properties.Remove($prop) } } diff --git a/libexec/scoop-hold.ps1 b/libexec/scoop-hold.ps1 index 79ee990dde..2d52310c79 100644 --- a/libexec/scoop-hold.ps1 +++ b/libexec/scoop-hold.ps1 @@ -34,7 +34,7 @@ $apps | ForEach-Object { if ($app -eq 'scoop') { $hold_update_until = [System.DateTime]::Now.AddDays(1) - set_config 'hold_update_until' $hold_update_until.ToString('o') | Out-Null + set_config HOLD_UPDATE_UNTIL $hold_update_until.ToString('o') | Out-Null success "$app is now held and might not be updated until $($hold_update_until.ToLocalTime())." return } @@ -47,7 +47,7 @@ $apps | ForEach-Object { return } - if (get_config NO_JUNCTIONS) { + if (get_config NO_JUNCTION){ $version = Select-CurrentVersion -App $app -Global:$global } else { $version = 'current' diff --git a/libexec/scoop-unhold.ps1 b/libexec/scoop-unhold.ps1 index b45b124888..e678247972 100644 --- a/libexec/scoop-unhold.ps1 +++ b/libexec/scoop-unhold.ps1 @@ -33,7 +33,7 @@ $apps | ForEach-Object { $app = $_ if ($app -eq 'scoop') { - set_config 'hold_update_until' $null | Out-Null + set_config HOLD_UPDATE_UNTIL $null | Out-Null success "$app is no longer held and can be updated again." return } @@ -46,7 +46,7 @@ $apps | ForEach-Object { return } - if (get_config NO_JUNCTIONS) { + if (get_config NO_JUNCTION){ $version = Select-CurrentVersion -App $app -Global:$global } else { $version = 'current' diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index 5c6a4c3921..c99cbdb4e3 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -54,7 +54,7 @@ if(($PSVersionTable.PSVersion.Major) -lt 5) { Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows" break } -$show_update_log = get_config 'show_update_log' $true +$show_update_log = get_config SHOW_UPDATE_LOG $true function update_scoop($show_update_log) { # Test if Scoop Core is hold @@ -102,7 +102,7 @@ function update_scoop($show_update_log) { # Stash uncommitted changes if (git -C "$currentdir" diff HEAD --name-only) { - if (get_config autostash_on_conflict) { + if (get_config AUTOSTASH_ON_CONFLICT) { warn "Uncommitted changes detected. Stashing..." git -C "$currentdir" stash push -m "WIP at $([System.DateTime]::Now.ToString('o'))" -u -q } else { @@ -321,7 +321,7 @@ if (-not ($apps -or $all)) { } update_scoop $show_update_log update_bucket $show_update_log - set_config lastUpdate ([System.DateTime]::Now.ToString('o')) | Out-Null + set_config LAST_UPDATE ([System.DateTime]::Now.ToString('o')) | Out-Null success 'Scoop was updated successfully!' } else { if ($global -and !(is_admin)) { @@ -336,7 +336,7 @@ if (-not ($apps -or $all)) { if ($updateScoop) { update_scoop $show_update_log update_bucket $show_update_log - set_config lastUpdate ([System.DateTime]::Now.ToString('o')) | Out-Null + set_config LAST_UPDATE ([System.DateTime]::Now.ToString('o')) | Out-Null success 'Scoop was updated successfully!' } diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index ef4b84e2f6..112b1398be 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -66,7 +66,7 @@ $_ERR_NO_API_KEY = 16 $exit_code = 0 # Global API key: -$api_key = get_config virustotal_api_key +$api_key = get_config VIRUSTOTAL_API_KEY if (!$api_key) { abort ("VirusTotal API key is not configured`n" + " You could get one from https://www.virustotal.com/gui/my-apikey and set with`n" + diff --git a/test/Import-File-Tests.ps1 b/test/Import-File-Tests.ps1 index 0359e8069f..5aadcd3ade 100644 --- a/test/Import-File-Tests.ps1 +++ b/test/Import-File-Tests.ps1 @@ -66,7 +66,7 @@ Describe 'Style constraints for non-binary project files' { It 'file newlines are CRLF' -Skip:$(-not $files_exist) { $badFiles = @( foreach ($file in $files) { - $content = Get-Content -Raw $file.FullName + $content = [System.IO.File]::ReadAllText($file.FullName) if (!$content) { throw "File contents are null: $($file.FullName)" } diff --git a/test/Scoop-Depends.Tests.ps1 b/test/Scoop-Depends.Tests.ps1 index 03713c0c3e..b465d28220 100644 --- a/test/Scoop-Depends.Tests.ps1 +++ b/test/Scoop-Depends.Tests.ps1 @@ -46,14 +46,14 @@ Describe 'Package Dependencies' -Tag 'Scoop' { Get-InstallationHelper -Manifest $manifest2 -Architecture '32bit' | Should -Be @('7zip') } It 'Helpers reflect config changes' { - Mock get_config { $false } -ParameterFilter { $name -eq 'MSIEXTRACT_USE_LESSMSI' } - Mock get_config { $true } -ParameterFilter { $name -eq '7ZIPEXTRACT_USE_EXTERNAL' } + Mock get_config { $false } -ParameterFilter { $name -eq 'USE_LESSMSI' } + Mock get_config { $true } -ParameterFilter { $name -eq 'USE_EXTERNAL_7ZIP' } Get-InstallationHelper -Manifest $manifest1 -Architecture '32bit' | Should -BeNullOrEmpty Get-InstallationHelper -Manifest $manifest2 -Architecture '32bit' | Should -BeNullOrEmpty } It 'Not return installed helpers' { - Mock get_config { $true } -ParameterFilter { $name -eq 'MSIEXTRACT_USE_LESSMSI' } - Mock get_config { $false } -ParameterFilter { $name -eq '7ZIPEXTRACT_USE_EXTERNAL' } + Mock get_config { $true } -ParameterFilter { $name -eq 'USE_LESSMSI' } + Mock get_config { $false } -ParameterFilter { $name -eq 'USE_EXTERNAL_7ZIP' } Mock Test-HelperInstalled { $true }-ParameterFilter { $Helper -eq '7zip' } Mock Test-HelperInstalled { $false }-ParameterFilter { $Helper -eq 'Lessmsi' } Get-InstallationHelper -Manifest $manifest1 -Architecture '32bit' | Should -Be @('lessmsi') @@ -68,7 +68,7 @@ Describe 'Package Dependencies' -Tag 'Scoop' { Context 'Dependencies resolution' { BeforeAll { Mock Test-HelperInstalled { $false } - Mock get_config { $true } -ParameterFilter { $name -eq 'MSIEXTRACT_USE_LESSMSI' } + Mock get_config { $true } -ParameterFilter { $name -eq 'USE_LESSMSI' } Mock Get-Manifest { 'lessmsi', @{}, $null, $null } -ParameterFilter { $app -eq 'lessmsi' } Mock Get-Manifest { '7zip', @{ url = 'test.msi' }, $null, $null } -ParameterFilter { $app -eq '7zip' } Mock Get-Manifest { 'innounp', @{}, $null, $null } -ParameterFilter { $app -eq 'innounp' }