Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): Change config option to snake_case in file and SCREAMING_CASE in code #5116

Merged
merged 5 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
66 changes: 42 additions & 24 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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"
Expand All @@ -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
}

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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
}
Expand All @@ -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 <YYYY-MM-DD>/<YYYY/MM/DD>'."
}
set_config hold_update_until $null | Out-Null
set_config HOLD_UPDATE_UNTIL $null | Out-Null
return $false
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1196,31 +1199,46 @@ 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
$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
}
}
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
6 changes: 3 additions & 3 deletions lib/decompress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/depends.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 *')) {
Expand Down
16 changes: 8 additions & 8 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)'"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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"

Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/unix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-cat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (!$app) { error '<app> 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 {
Expand Down
4 changes: 2 additions & 2 deletions libexec/scoop-checkup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}

Expand Down
Loading