diff --git a/.github/ISSUE_TEMPLATE/Bug.md b/.github/ISSUE_TEMPLATE/Bug.md index 23c6945359..b9202d9571 100644 --- a/.github/ISSUE_TEMPLATE/Bug.md +++ b/.github/ISSUE_TEMPLATE/Bug.md @@ -1,6 +1,6 @@ --- name: Bug -about: A problem which makes it impossible to use Scoop. +about: A problem which makes it impossible to use Shovel. labels: bug --- diff --git a/.github/ISSUE_TEMPLATE/Enhancement.md b/.github/ISSUE_TEMPLATE/Enhancement.md index 23747c7345..24325aa2e7 100644 --- a/.github/ISSUE_TEMPLATE/Enhancement.md +++ b/.github/ISSUE_TEMPLATE/Enhancement.md @@ -1,7 +1,7 @@ --- name: Enhancement -about: Some feature, idea or enhancement to improve Scoop. +about: Some feature, idea or enhancement to improve Shovel. labels: enhancement --- - + diff --git a/bin/auto-pr.ps1 b/bin/auto-pr.ps1 index e71b84386b..58cd507c58 100644 --- a/bin/auto-pr.ps1 +++ b/bin/auto-pr.ps1 @@ -4,23 +4,23 @@ .DESCRIPTION Updates manifests and pushes them directly to the master branch or creates pull-requests for upstream. .PARAMETER Upstream - Upstream repository with the target branch. + Specifies the upstream repository with the target branch. Must be in format '/:' .PARAMETER App - Manifest name to search. - Placeholders are supported. + Specifies the manifest name to search. + Wildcards are supported. .PARAMETER Dir - The directory where to search for manifests. + Specifies the location of manifests. .PARAMETER Push - Push updates directly to 'origin master'. + Specifies to push updates directly to 'origin master'. .PARAMETER Request - Create pull-requests on 'upstream master' for each update. + Specifies to create pull-requests on 'upstream master' for each update instead of direct pushing. .PARAMETER Help - Print help to console. + Specifies to print help to console. .PARAMETER SpecialSnowflakes - An array of manifests, which should be updated all the time. (-ForceUpdate parameter to checkver) + Specifies an array of manifest names, which should be updated all the time. (-ForceUpdate parameter to checkver) .PARAMETER SkipUpdated - Updated manifests will not be shown. + Specifies to not show up-to-date manifests. .PARAMETER SkipCheckver Specifies to skip checkver execution. .EXAMPLE @@ -29,25 +29,24 @@ PS BUCKETROOT > .\bin\auto-pr.ps1 -Push Update all manifests inside 'bucket/' directory. #> - param( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory)] [ValidateScript( { - if (!($_ -match '^(.*)\/(.*):(.*)$')) { throw 'Upstream must be in this format: /:' } - $true - })] + if ($_ -notmatch '^(.*)\/(.*):(.*)$') { throw 'Upstream must be in format: /:' } + $true + })] [String] $Upstream, [String] $App = '*', - [Parameter(Mandatory = $true)] + [Parameter(Mandatory)] [ValidateScript( { - if (!(Test-Path $_ -Type Container)) { throw "$_ is not a directory!" } - $true - })] + if (!(Test-Path $_ -Type 'Container')) { throw "$_ is not a directory!" } + $true + })] [String] $Dir, [Switch] $Push, [Switch] $Request, [Switch] $Help, - [string[]] $SpecialSnowflakes, + [String[]] $SpecialSnowflakes, [Switch] $SkipUpdated, [Switch] $SkipCheckver ) @@ -60,23 +59,23 @@ $Upstream | Out-Null # PowerShell/PSScriptAnalyzer#1472 $Dir = Resolve-Path $Dir -if ((!$Push -and !$Request) -or $Help) { - Write-Host @' +if ($Help -or (!$Push -and !$Request)) { + Write-UserMessage @' Usage: auto-pr.ps1 [OPTION] Mandatory options: - -p, -push push updates directly to 'origin master' - -r, -request create pull-requests on 'upstream master' for each update + -p, -push Push updates directly to 'origin master' + -r, -request Create pull-requests on 'upstream master' for each update Optional options: - -u, -upstream upstream repository with target branch - only used if -r is set (default: lukesampson/scoop:master) + -u, -upstream Upstream repository with target branch + Only used if -r is set (default: lukesampson/scoop:master) -h, -help '@ exit 0 } -if (!(Get-Command -Name 'hub' -CommandType Application -ErrorAction SilentlyContinue)) { +if (!(Get-Command -Name 'hub' -CommandType 'Application' -ErrorAction 'SilentlyContinue')) { Stop-ScoopExecution -Message 'hub is required! Please refer to ''https://hub.github.com/'' to find out how to get hub for your platform.' } @@ -89,25 +88,26 @@ function execute($cmd) { return $output } +# json object, application name, upstream repository, relative path to manifest file function pull_requests($json, [String] $app, [String] $upstream, [String] $manifest) { $version = $json.version $homepage = $json.homepage $branch = "manifest/$app-$version" execute 'hub checkout master' - Write-Host "hub rev-parse --verify $branch" -ForegroundColor Green + Write-UserMessage "hub rev-parse --verify $branch" -ForegroundColor 'Green' hub rev-parse --verify $branch if ($LASTEXITCODE -eq 0) { - Write-Host "Skipping update $app ($version) ..." -ForegroundColor Yellow + Write-UserMessage "Skipping update $app ($version) ..." -ForegroundColor 'Yellow' return } - Write-Host "Creating update $app ($version) ..." -ForegroundColor DarkCyan + Write-UserMessage "Creating update $app ($version) ..." -ForegroundColor 'DarkCyan' execute "hub checkout -b $branch" execute "hub add $manifest" execute "hub commit -m '${app}: Update to version $version'" - Write-Host "Pushing update $app ($version) ..." -ForegroundColor DarkCyan + Write-UserMessage "Pushing update $app ($version) ..." -ForegroundColor 'DarkCyan' execute "hub push origin $branch" if ($LASTEXITCODE -gt 0) { @@ -116,12 +116,12 @@ function pull_requests($json, [String] $app, [String] $upstream, [String] $manif return } - Start-Sleep 1 - Write-Host "Pull-Request update $app ($version) ..." -ForegroundColor DarkCyan - Write-Host "hub pull-request -m '' -b '$upstream' -h '$branch'" -ForegroundColor Green + Start-Sleep -Seconds 1 + Write-UserMessage "Pull-Request update $app ($version) ..." -ForegroundColor 'DarkCyan' + Write-UserMessage "hub pull-request -m '' -b '$upstream' -h '$branch'" -ForegroundColor 'Green' $msg = @" -$app`: Update to version $version +${app}: Update to version $version Hello lovely humans, a new version of [$app]($homepage) is available. @@ -138,7 +138,7 @@ a new version of [$app]($homepage) is available. } } -Write-Host 'Updating ...' -ForegroundColor DarkCyan +Write-UserMessage 'Updating ...' -ForegroundColor 'DarkCyan' if ($Push) { execute 'hub pull origin master' execute 'hub checkout master' @@ -148,11 +148,11 @@ if ($Push) { } if (!$SkipCheckver) { - . "$PSScriptRoot\checkver.ps1" -App $App -Dir $Dir -Update -SkipUpdated:$SkipUpdated + & "$PSScriptRoot\checkver.ps1" -App $App -Dir $Dir -Update -SkipUpdated:$SkipUpdated if ($SpecialSnowflakes) { - Write-UserMessage -Message "Forcing update on our special snowflakes: $($SpecialSnowflakes -join ',')" -Color DarkCyan + Write-UserMessage -Message "Forcing update on special snowflakes: $($SpecialSnowflakes -join ',')" -Color 'DarkCyan' $SpecialSnowflakes -split ',' | ForEach-Object { - . "$PSScriptRoot\checkver.ps1" $_ -Dir $Dir -ForceUpdate + & "$PSScriptRoot\checkver.ps1" $_ -Dir $Dir -ForceUpdate } } } @@ -170,16 +170,16 @@ hub diff --name-only | ForEach-Object { $version = $json.version if ($Push) { - Write-Host "Creating update $app ($version) ..." -ForegroundColor DarkCyan + Write-UserMessage "Creating update $app ($version) ..." -ForegroundColor 'DarkCyan' execute "hub add $manifest" - # detect if file was staged, because it's not when only LF or CRLF have changed + # Detect if file was staged, because it's not when only LF or CRLF have changed $status = execute 'hub status --porcelain -uno' $status = $status | Where-Object { $_ -match "M\s{2}.*$app.json" } if ($status -and $status.StartsWith('M ') -and $status.EndsWith("$app.json")) { execute "hub commit -m '${app}: Update to version $version'" } else { - Write-Host "Skipping $app because only LF/CRLF changes were detected ..." -ForegroundColor Yellow + Write-UserMessage "Skipping $app because only LF/CRLF changes were detected ..." -Info } } else { pull_requests $json $app $Upstream $manifest @@ -187,10 +187,10 @@ hub diff --name-only | ForEach-Object { } if ($Push) { - Write-Host 'Pushing updates ...' -ForegroundColor DarkCyan + Write-UserMessage 'Pushing updates ...' -ForegroundColor 'DarkCyan' execute 'hub push origin master' } else { - Write-Host 'Returning to master branch and removing unstaged files ...' -ForegroundColor DarkCyan + Write-UserMessage 'Returning to master branch and removing unstaged files ...' -ForegroundColor 'DarkCyan' execute 'hub checkout -f master' } diff --git a/bin/checkhashes.ps1 b/bin/checkhashes.ps1 index 83776b274e..92a9edf637 100644 --- a/bin/checkhashes.ps1 +++ b/bin/checkhashes.ps1 @@ -1,19 +1,19 @@ <# .SYNOPSIS - Check if ALL urls inside manifest have correct hashes. + Check if all urls defined in manifest have correct hashes. .PARAMETER App - Manifest to be checked. + Specifies the manifest name to be checked (without extension). Wildcards are supported. .PARAMETER Dir - Where to search for manifest(s). + Specifies the location of manifests. .PARAMETER Update - When there are mismatched hashes, manifest will be updated. + Specifies to update the manifest file with updated hashes. .PARAMETER ForceUpdate - Manifest will be updated all the time. Not only when there are mismatched hashes. + Specifies to update the manifest file even without hashes were not changed. .PARAMETER SkipCorrect - Manifests without mismatch will not be shown. + Specifies to not show manifest without mismatched hashes. .PARAMETER UseCache - Downloaded files will not be deleted after script finish. + Specifies to not delete downloaded files from cache. Should not be used, because check should be used for downloading actual version of file (as normal user, not finding in some document from vendors, which could be damaged / wrong (Example: Slack@3.3.1 lukesampson/scoop-extras#1192)), not some previously downloaded. .EXAMPLE PS BUCKETROOT> .\bin\checkhashes.ps1 @@ -25,11 +25,11 @@ param( [SupportsWildcards()] [String] $App = '*', - [Parameter(Mandatory = $true)] + [Parameter(Mandatory)] [ValidateScript( { - if (!(Test-Path $_ -Type Container)) { throw "$_ is not a directory!" } - $true - })] + if (!(Test-Path $_ -Type 'Container')) { throw "$_ is not a directory!" } + $true + })] [String] $Dir, [Switch] $Update, [Switch] $ForceUpdate, @@ -45,11 +45,10 @@ param( $Dir = Resolve-Path $Dir if ($ForceUpdate) { $Update = $true } # Cleanup -if (!$UseCache) { Join-Path $SCOOP_CACHE_DIRECTORY '*HASH_CHECK*' | Remove-Item -ErrorAction SilentlyContinue -Force -Recurse } +if (!$UseCache) { Join-Path $SCOOP_CACHE_DIRECTORY '*HASH_CHECK*' | Remove-Item -ErrorAction 'SilentlyContinue' -Force -Recurse } function err ([String] $name, [String[]] $message) { - Write-Host "$name`: " -ForegroundColor Red -NoNewline - Write-Host ($message -join "`r`n") -ForegroundColor Red + Write-UserMessage "${name}: ", ($message -join "`r`n") -Color 'Red' } $MANIFESTS = @() @@ -91,9 +90,6 @@ foreach ($single in Get-ChildItem $Dir "$App.*" -File) { } } -# Clear any existing events -Get-Event | ForEach-Object { Remove-Event $_.SourceIdentifier } - foreach ($current in $MANIFESTS) { $count = 0 # Array of indexes mismatched hashes. @@ -134,19 +130,19 @@ foreach ($current in $MANIFESTS) { if ($mismatched.Length -eq 0 ) { if (!$SkipCorrect) { Write-Host "$($current.app): " -NoNewline - Write-Host 'OK' -ForegroundColor Green + Write-Host 'OK' -ForegroundColor 'Green' } } else { Write-Host "$($current.app): " -NoNewline - Write-Host 'Mismatch found ' -ForegroundColor Red + Write-Host 'Mismatch found ' -ForegroundColor 'Red' $mismatched | ForEach-Object { $file = cache_path $current.app $version $current.urls[$_] Write-UserMessage -Message "`tURL:`t`t$($current.urls[$_])" if (Test-Path $file) { Write-UserMessage -Message "`tFirst bytes:`t$(Get-MagicByte -File $file -Pretty)" } - Write-UserMessage -Message "`tExpected:`t$($current.hashes[$_])" -Color Green - Write-UserMessage -Message "`tActual:`t`t$($actuals[$_])" -Color Red + Write-UserMessage -Message "`tExpected:`t$($current.hashes[$_])" -Color 'Green' + Write-UserMessage -Message "`tActual:`t`t$($actuals[$_])" -Color 'Red' } } @@ -154,7 +150,7 @@ foreach ($current in $MANIFESTS) { if ($current.manifest.url -and $current.manifest.hash) { $current.manifest.hash = $actuals } else { - $platforms = ($current.manifest.architecture | Get-Member -MemberType NoteProperty).Name + $platforms = ($current.manifest.architecture | Get-Member -MemberType 'NoteProperty').Name # Defaults to zero, don't know, which architecture is available $64bit_count = 0 $32bit_count = 0 @@ -171,7 +167,7 @@ foreach ($current in $MANIFESTS) { } } - Write-UserMessage -Message "Writing updated $($current.app) manifest" -Color DarkGreen + Write-UserMessage -Message "Writing updated $($current.app) manifest" -Color 'DarkGreen' $p = Join-Path $Dir "$($current.app).json" diff --git a/bin/checkurls.ps1 b/bin/checkurls.ps1 index 8794ce9108..4b94713bce 100644 --- a/bin/checkurls.ps1 +++ b/bin/checkurls.ps1 @@ -2,23 +2,23 @@ .SYNOPSIS List manifests which do not have valid URLs. .PARAMETER App - Manifest name to search. - Wildcards is supported. + Specifies the manifest name to search. + Wildcards are supported. .PARAMETER Dir - Where to search for manifest(s). + Specifies the location of manifests. .PARAMETER Timeout - How long (seconds) the request can be pending before it times out. + Specifies how long (seconds) the request can be pending before it times out. .PARAMETER SkipValid - Manifests will all valid URLs will not be shown. + Specifies to not show manifests, which have all URLs valid. #> param( [SupportsWildcards()] [String] $App = '*', - [Parameter(Mandatory = $true)] + [Parameter(Mandatory)] [ValidateScript( { - if (!(Test-Path $_ -Type Container)) { throw "$_ is not a directory!" } - $true - })] + if (!(Test-Path $_ -Type 'Container')) { throw "$_ is not a directory!" } + $true + })] [String] $Dir, [Int] $Timeout = 5, [Switch] $SkipValid @@ -39,13 +39,13 @@ Get-ChildItem $Dir "$App.*" -File | ForEach-Object { } Write-Host '[' -NoNewline -Write-Host 'U' -NoNewline -ForegroundColor Cyan +Write-Host 'U' -ForegroundColor 'Cyan' -NoNewline Write-Host ']RLs' Write-Host ' | [' -NoNewline -Write-Host 'O' -NoNewline -ForegroundColor Green +Write-Host 'O' -ForegroundColor 'Green' -NoNewline Write-Host ']kay' Write-Host ' | | [' -NoNewline -Write-Host 'F' -NoNewline -ForegroundColor Red +Write-Host 'F' -ForegroundColor 'Red' -NoNewline Write-Host ']ailed' Write-Host ' | | |' @@ -103,7 +103,7 @@ foreach ($man in $Queue) { # URLS Write-Host '[' -NoNewline - Write-Host $urls.Length -NoNewline -ForegroundColor Cyan + Write-Host $urls.Length -ForegroundColor 'Cyan' -NoNewline Write-Host ']' -NoNewline # Okay @@ -125,6 +125,6 @@ foreach ($man in $Queue) { Write-Host (strip_ext $name) $errors | ForEach-Object { - Write-Host " > $_" -ForegroundColor DarkRed + Write-Host " > $_" -ForegroundColor 'DarkRed' } } diff --git a/bin/checkver.ps1 b/bin/checkver.ps1 index 2f2ccc1137..6784874b72 100644 --- a/bin/checkver.ps1 +++ b/bin/checkver.ps1 @@ -4,17 +4,17 @@ .DESCRIPTION Checks websites for newer versions using an (optional) regular expression defined in the manifest. .PARAMETER App - Manifest name to search. + Specifies the manifest name. Wildcards are supported. .PARAMETER Dir - Where to search for manifest(s). + Specifies the location of manifests. .PARAMETER Update - Update given manifest + Specifies to write updated manifest into file. .PARAMETER ForceUpdate - Update given manifest(s) even when there is no new version. - Useful for hash updates. + Specifies to write given manifest(s) even when there is no new version. + Useful for hash updates or formating. .PARAMETER SkipUpdated - Updated manifests will not be shown. + Specifies to not show up-to-date manifests. .EXAMPLE PS BUCKETROOT > .\bin\checkver.ps1 Check all manifest inside default directory. @@ -51,9 +51,9 @@ param( [String] $App = '*', [Parameter(Mandatory)] [ValidateScript( { - if (!(Test-Path $_ -Type Container)) { throw "$_ is not a directory!" } - $true - })] + if (!(Test-Path $_ -Type 'Container')) { throw "$_ is not a directory!" } + $true + })] [String] $Dir, [Switch] $Update, [Switch] $ForceUpdate, @@ -79,7 +79,7 @@ $GITHUB_REGEX = "/releases/tag/$UNIVERSAL_REGEX" #region Functions function next($AppName, $Err) { Write-Host "${AppName}: " -NoNewline - Write-UserMessage -Message $Err -Color DarkRed + Write-UserMessage -Message $Err -Color 'DarkRed' # Just throw something to invoke try-catch throw 'error' @@ -181,16 +181,16 @@ function Invoke-Check { # version hasn't changed (step over if forced update) if ($ver -eq $expectedVersion -and !$ForceUpdate) { - Write-UserMessage -Message $ver -Color DarkGreen + Write-UserMessage -Message $ver -Color 'DarkGreen' return } - Write-Host $ver -ForegroundColor DarkRed -NoNewline + Write-Host $ver -ForegroundColor 'DarkRed' -NoNewline Write-Host " (scoop version is $expectedVersion)" -NoNewline $updateAvailable = (Compare-Version -ReferenceVersion $expectedVersion -DifferenceVersion $ver) -ne 0 if ($json.autoupdate -and $updateAvailable) { - Write-UserMessage -Message ' autoupdate available' -Color Cyan + Write-UserMessage -Message ' autoupdate available' -Color 'Cyan' } else { Write-UserMessage -Message '' } @@ -199,10 +199,10 @@ function Invoke-Check { if ($ForceUpdate) { $Update = $true } if ($Update -and $json.autoupdate) { - if ($ForceUpdate) { Write-UserMessage -Message 'Forcing autoupdate!' -Color DarkMagenta } - try { - if ($Version -ne '') { $ver = $Version } + if ($ForceUpdate) { Write-UserMessage -Message 'Forcing autoupdate!' -Color 'DarkMagenta' } + if ($Version -ne '') { $ver = $Version } + try { Invoke-Autoupdate $appName $Dir $json $ver $matchesHashtable } catch { Write-UserMessage -Message $_.Exception.Message -Err diff --git a/bin/describe.ps1 b/bin/describe.ps1 index a5fbd7d601..34e15ad2d6 100644 --- a/bin/describe.ps1 +++ b/bin/describe.ps1 @@ -2,19 +2,19 @@ .SYNOPSIS Search for application description on homepage. .PARAMETER App - Manifest name to search. + Specifies the manifest name. Wildcards are supported. .PARAMETER Dir - Where to search for manifest(s). + Specifies the location of manifests. #> param( [SupportsWildcards()] [String] $App = '*', [Parameter(Mandatory)] [ValidateScript( { - if (!(Test-Path $_ -Type Container)) { throw "$_ is not a directory!" } - $true - })] + if (!(Test-Path $_ -Type 'Container')) { throw "$_ is not a directory!" } + $true + })] [String] $Dir ) @@ -50,12 +50,12 @@ $Queue | ForEach-Object { $description, $descr_method = find_description $manifest.homepage $home_html if (!$description) { - Write-UserMessage -Message "`nDescription not found ($($manifest.homepage))" -Color Red + Write-UserMessage -Message "`nDescription not found ($($manifest.homepage))" -Color 'Red' return } $description = clean_description $description Write-UserMessage -Message "(found by $descr_method)" - Write-UserMessage -Message " ""$description""" -Color Green + Write-UserMessage -Message " ""$description""" -Color 'Green' } diff --git a/bin/formatjson.ps1 b/bin/formatjson.ps1 index 05386ded2c..af835af197 100644 --- a/bin/formatjson.ps1 +++ b/bin/formatjson.ps1 @@ -2,9 +2,10 @@ .SYNOPSIS Format manifest. .PARAMETER App - Manifest to format. + Specifies the manifest name. + Wildcards are supported. .PARAMETER Dir - Where to search for manifest(s). + Specifies the location of manifests. .EXAMPLE PS BUCKETROOT> .\bin\formatjson.ps1 Format all manifests inside bucket directory. @@ -17,9 +18,9 @@ param( [String] $App = '*', [Parameter(Mandatory)] [ValidateScript( { - if (!(Test-Path $_ -Type Container)) { throw "$_ is not a directory!" } - $true - })] + if (!(Test-Path $_ -Type 'Container')) { throw "$_ is not a directory!" } + $true + })] [String] $Dir ) @@ -40,7 +41,7 @@ foreach ($m in Get-ChildItem $Dir "$App.*" -File) { $name = $m.Basename #region Migrations and fixes - # Checkver + #region Checkver $checkver = $manifest.checkver if ($checkver -and ($checkver.GetType() -ne [System.String])) { # Remove not needed url @@ -52,14 +53,14 @@ foreach ($m in Get-ChildItem $Dir "$App.*" -File) { if ($checkver.jp) { _infoMes $name 'checkver.jp -> checkver.jsonpath' - $checkver | Add-Member -MemberType NoteProperty -Name 'jsonpath' -Value $checkver.jp + $checkver | Add-Member -MemberType 'NoteProperty' -Name 'jsonpath' -Value $checkver.jp $checkver.PSObject.Properties.Remove('jp') } if ($checkver.re) { _infoMes $name 'checkver.re -> checkver.regex' - $checkver | Add-Member -MemberType NoteProperty -Name 'regex' -Value $checkver.re + $checkver | Add-Member -MemberType 'NoteProperty' -Name 'regex' -Value $checkver.re $checkver.PSObject.Properties.Remove('re') if ($checkver.reverse) { @@ -67,7 +68,7 @@ foreach ($m in Get-ChildItem $Dir "$App.*" -File) { $rev = $checkver.reverse $checkver.PSObject.Properties.Remove('reverse') - $checkver | Add-Member -MemberType NoteProperty -Name 'reverse' -Value $rev + $checkver | Add-Member -MemberType 'NoteProperty' -Name 'reverse' -Value $rev } } @@ -82,7 +83,7 @@ foreach ($m in Get-ChildItem $Dir "$App.*" -File) { $repl = $checkver.replace $checkver.PSObject.Properties.Remove('replace') - $checkver | Add-Member -MemberType NoteProperty -Name 'replace' -Value $repl + $checkver | Add-Member -MemberType 'NoteProperty' -Name 'replace' -Value $repl } # Only one github property and homepage is set to github repository @@ -94,8 +95,9 @@ foreach ($m in Get-ChildItem $Dir "$App.*" -File) { $manifest.checkver = $checkver } + #endregion Checkver - # Architecture properties sort + #region Architecture properties sort foreach ($mainProp in 'architecture', 'autoupdate') { if ($mainProp -eq 'autoupdate') { if ($manifest.$mainProp.architecture) { @@ -117,7 +119,7 @@ foreach ($m in Get-ChildItem $Dir "$App.*" -File) { $newArch = [PSCustomObject] @{ } '64bit', '32bit' | ForEach-Object { - if ($arch.$_) { $newArch | Add-Member -MemberType NoteProperty -Name $_ -Value $arch.$_ } + if ($arch.$_) { $newArch | Add-Member -MemberType 'NoteProperty' -Name $_ -Value $arch.$_ } } if ($arch.PSObject.Properties.Name[0] -ne '64bit') { @@ -131,18 +133,19 @@ foreach ($m in Get-ChildItem $Dir "$App.*" -File) { $manifest.$mainProp = $newArch } } + #endregion Architecture properties sort $newManifest = [PSCustomObject] @{ } - '##', '_comment', 'version', 'description', 'homepage', 'license', 'notes', 'depends' | ForEach-Object { + '##', '_comment', 'version', 'description', 'homepage', 'license', 'notes', 'changelog', 'depends' | ForEach-Object { if ($manifest.$_) { - $newManifest | Add-Member -MemberType NoteProperty -Name $_ -Value $manifest.$_ + $newManifest | Add-Member -MemberType 'NoteProperty' -Name $_ -Value $manifest.$_ $manifest.PSObject.Properties.Remove($_) } } # Add remaining properties in same order $manifest.PSObject.Properties.Name | ForEach-Object { - $newManifest | Add-Member -MemberType NoteProperty -Name $_ -Value $manifest.$_ + $newManifest | Add-Member -MemberType 'NoteProperty' -Name $_ -Value $manifest.$_ } $manifest = $newManifest diff --git a/bin/missing-checkver.ps1 b/bin/missing-checkver.ps1 index 7f3f7c8470..d16974c17e 100644 --- a/bin/missing-checkver.ps1 +++ b/bin/missing-checkver.ps1 @@ -2,21 +2,21 @@ .SYNOPSIS Check if manifest contains checkver and autoupdate property. .PARAMETER App - Manifest name. - Wirldcards are supported. + Specifies the manifest name. + Wildcards are supported. .PARAMETER Dir - Location of manifests. + Specifies the location of manifests. .PARAMETER SkipSupported - Manifests with checkver and autoupdate will not be presented. + Specifies to not show manifests with checkver and autoupdate properties. #> param( [SupportsWildcards()] [String] $App = '*', - [Parameter(Mandatory = $true)] + [Parameter(Mandatory)] [ValidateScript( { - if (!(Test-Path $_ -Type Container)) { throw "$_ is not a directory!" } - $true - })] + if (!(Test-Path $_ -Type 'Container')) { throw "$_ is not a directory!" } + $true + })] [String] $Dir, [Switch] $SkipSupported ) @@ -30,10 +30,10 @@ $SkipSupported | Out-Null # PowerShell/PSScriptAnalyzer#1472 $Dir = Resolve-Path $Dir Write-Host '[' -NoNewline -Write-Host 'C' -NoNewline -ForegroundColor Green +Write-Host 'C' -ForegroundColor 'Green' -NoNewline Write-Host ']heckver' Write-Host ' | [' -NoNewline -Write-Host 'A' -NoNewline -ForegroundColor Cyan +Write-Host 'A' -ForegroundColor 'Cyan' -NoNewline Write-Host ']utoupdate' Write-Host ' | |' @@ -43,11 +43,11 @@ Get-ChildItem $Dir "$App.*" -File | ForEach-Object { if ($SkipSupported -and $json.checkver -and $json.autoupdate) { return } Write-Host '[' -NoNewline - Write-Host $(if ($json.checkver) { 'C' } else { ' ' }) -NoNewline -ForegroundColor Green + Write-Host $(if ($json.checkver) { 'C' } else { ' ' }) -ForegroundColor 'Green' -NoNewline Write-Host ']' -NoNewline Write-Host '[' -NoNewline - Write-Host $(if ($json.autoupdate) { 'A' } else { ' ' }) -NoNewline -ForegroundColor Cyan + Write-Host $(if ($json.autoupdate) { 'A' } else { ' ' }) -ForegroundColor 'Cyan' -NoNewline Write-Host '] ' -NoNewline - Write-Host (strip_ext $_.Name) + Write-Host $_.BaseName } diff --git a/bin/uninstall.ps1 b/bin/uninstall.ps1 index 4e250aa252..6e607d805d 100644 --- a/bin/uninstall.ps1 +++ b/bin/uninstall.ps1 @@ -2,9 +2,9 @@ .SYNOPSIS Uninstall ALL scoop applications and scoop itself. .PARAMETER global - Global applications will be uninstalled. + Specifies to uninstall global applications. .PARAMETER purge - Persisted data will be deleted. + Specifies to delete persisted data. #> param( [bool] $global, diff --git a/bin/update-supporting.ps1 b/bin/update-supporting.ps1 index 45fe2a14f1..77bf79a2e6 100644 --- a/bin/update-supporting.ps1 +++ b/bin/update-supporting.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Update supporting tools to the latest version. .PARAMETER Supporting - Name of supporting tool to be updated. + Specifies the name of supporting tool to be updated. #> param([String] $Supporting = '*') @@ -10,22 +10,23 @@ param([String] $Supporting = '*') . (Join-Path $PSScriptRoot "..\lib\$_.ps1") } -$Sups = Join-Path $PSScriptRoot '..\supporting\*' | Get-ChildItem -File -Include "$Supporting.*" +$Sups = Join-Path $PSScriptRoot '..\supporting\*' | Get-ChildItem -Include "$Supporting.*" -File foreach ($sup in $Sups) { $name = $sup.BaseName $folder = $sup.Directory $dir = Join-Path $folder "$name\bin" - Write-UserMessage -Message "Updating $name" -Color Magenta + Write-UserMessage -Message "Updating $name" -Color 'Magenta' $checkver = Join-Path $PSScriptRoot 'checkver.ps1' - Invoke-Expression "& $checkver -App $name -Dir $folder -Update" + & "$checkver" -App "$name" -Dir "$folder" -Update $manifest = parse_json $sup.FullName - ensure $dir | Out-Null + Confirm-DirectoryExistence -Path $dir | Out-Null - dl_urls $name $manifest.version $manifest '' default_architecture $dir $true $true | Out-Null + $fname = dl_urls $name $manifest.version $manifest '' 'default_architecture' $dir $true $true + $fname | Out-Null # Pre install is enough now pre_install $manifest $architecture diff --git a/lib/Alias.ps1 b/lib/Alias.ps1 index c00915c2a7..8ffb767984 100644 --- a/lib/Alias.ps1 +++ b/lib/Alias.ps1 @@ -5,6 +5,10 @@ $ALIAS_CMD_ALIAS = 'alias' function Get-AliasesFromConfig { + <# + .SYNOPSIS + Get hahstable of all aliases defined in config. + #> return get_config $ALIAS_CMD_ALIAS @{ } } @@ -71,7 +75,7 @@ $Command "@ # Add alias to config - $aliases | Add-Member -Name $Name -Value $aliasFileName -MemberType NoteProperty + $aliases | Add-Member -Name $Name -Value $aliasFileName -MemberType 'NoteProperty' set_config $ALIAS_CMD_ALIAS $aliases | Out-Null } @@ -105,7 +109,7 @@ function Get-ScoopAlias { param([Switch] $Verbose) $aliases = @() - $props = @((Get-AliasesFromConfig).PSObject.Properties | Where-Object -Property MemberType -EQ -Value NoteProperty) + $props = @((Get-AliasesFromConfig).PSObject.Properties | Where-Object -Property 'MemberType' -EQ -Value 'NoteProperty') if ($props.Count -eq 0) { $props = @() } $props.GetEnumerator() | ForEach-Object { diff --git a/lib/Diagnostic.ps1 b/lib/Diagnostic.ps1 index dbbd20d061..f4a760838b 100644 --- a/lib/Diagnostic.ps1 +++ b/lib/Diagnostic.ps1 @@ -9,6 +9,10 @@ Use 'Write-UserMessage -Warning' to highlight the issue, and follow up with the } function Test-Drive { + <# + .SYNOPSIS + Test disk drive requirements/configuration. + #> [CmdletBinding()] [OutputType([bool])] param() @@ -31,11 +35,15 @@ function Test-Drive { } function Test-WindowsDefender { + <# + .SYNOPSIS + Test windows defender exclusions. + #> [CmdletBinding()] [OutputType([bool])] param([Switch] $Global) - $defender = Get-Service -Name WinDefend -ErrorAction SilentlyContinue + $defender = Get-Service -Name 'WinDefend' -ErrorAction 'SilentlyContinue' if (($defender -and $defender.Status) -and ($defender.Status -eq [System.ServiceProcess.ServiceControllerStatus]::Running)) { if (Test-CommandAvailable -Command 'Get-MpPreference') { $installPath = if ($Global) { $SCOOP_GLOBAL_ROOT_DIRECTORY } else { $SCOOP_ROOT_DIRECTORY } @@ -58,12 +66,16 @@ function Test-WindowsDefender { } function Test-MainBucketAdded { + <# + .SYNOPSIS + Test if main bucket was added after migration from core repository. + #> [CmdletBinding()] [OutputType([bool])] param() if ((Get-LocalBucket) -notcontains 'main') { - Write-UserMessage -Message 'Main bucket is not added.' -Warning + Write-UserMessage -Message '''main'' bucket is not added.' -Warning Write-UserMessage -Message @( ' Fixable with running following command in elevated prompt:' ' scoop bucket add main' @@ -76,6 +88,10 @@ function Test-MainBucketAdded { } function Test-LongPathEnabled { + <# + .SYNOPSIS + Test if long paths option is enabled. + #> [CmdletBinding()] [OutputType([bool])] param() @@ -86,7 +102,7 @@ function Test-LongPathEnabled { return $false } - $key = Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -ErrorAction SilentlyContinue + $key = Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -ErrorAction 'SilentlyContinue' if (!$key -or ($key.LongPathsEnabled -eq 0)) { Write-UserMessage -Message 'LongPaths support is not enabled.' -Warning Write-UserMessage -Message @( @@ -101,6 +117,10 @@ function Test-LongPathEnabled { } function Test-EnvironmentVariable { + <# + .SYNOPSIS + Test if scoop's related environment variables are defined. + #> [CmdletBinding()] [OutputType([bool])] param() @@ -108,8 +128,8 @@ function Test-EnvironmentVariable { $result = $true # Comspec - if (($null -eq $env:COMSPEC) -or (!(Test-Path $env:COMSPEC -PathType Leaf))) { - Write-UserMessage -Message '$env:COMSPEC is not configured' -Warning + if (($null -eq $env:COMSPEC) -or (!(Test-Path $env:COMSPEC -PathType 'Leaf'))) { + Write-UserMessage -Message '''COMSPEC'' is not configured' -Warning Write-UserMessage -Message @( ' By default the variable should points to the cmd.exe in Windows: ''%SystemRoot%\system32\cmd.exe''.' ' Fixable with running following command in elevated prompt:' @@ -120,7 +140,7 @@ function Test-EnvironmentVariable { # Scoop ENV if (!$env:SCOOP) { - Write-UserMessage -Message '$env:SCOOP is not configured' -Warning + Write-UserMessage -Message '''SCOOP'' is not configured' -Warning Write-UserMessage -Message @( ' SCOOP environment should be set as it is widely used by users and documentation to reference scoop installation directory' ' Fixable with running following command:' @@ -130,7 +150,7 @@ function Test-EnvironmentVariable { } if ($env:SCOOP -ne $SCOOP_ROOT_DIRECTORY) { - Write-UserMessage -Message 'SCOOP environment variable should be set to actual scoop installation location' -Warning + Write-UserMessage -Message '''SCOOP'' environment variable should be set to actual scoop installation location' -Warning Write-UserMessage -Message @( ' Fixable with running following command:' " [Environment]::SetEnvironmentVariable('SCOOP', '$SCOOP_ROOT_DIRECTORY', 'User')" @@ -142,13 +162,17 @@ function Test-EnvironmentVariable { } function Test-HelpersInstalled { + <# + .SYNOPSIS + Test if all widely used helpers are installed. + #> [CmdletBinding()] [OutputType([bool])] param() $result = $true - if (!(Test-HelperInstalled -Helper 7zip)) { + if (!(Test-HelperInstalled -Helper '7zip')) { Write-UserMessage -Message '''7-Zip'' not installed!. It is essential component for most of the manifests.' -Warning Write-UserMessage -Message @( ' Fixable with running following command:' @@ -160,8 +184,8 @@ function Test-HelpersInstalled { $result = $false } - if (!(Test-HelperInstalled -Helper Innounp)) { - Write-UserMessage -Message "'innounp' is not installed! It is essential component for extraction of InnoSetup based installers." -Warning + if (!(Test-HelperInstalled -Helper 'Innounp')) { + Write-UserMessage -Message '''innounp'' is not installed! It is essential component for extraction of InnoSetup based installers.' -Warning Write-UserMessage -Message @( ' Fixable with running following command:' ' scoop install innounp' @@ -169,8 +193,8 @@ function Test-HelpersInstalled { $result = $false } - if (!(Test-HelperInstalled -Helper Dark)) { - Write-UserMessage -Message "'dark' is not installed! It is essential component for extraction of WiX Toolset based installers." -Warning + if (!(Test-HelperInstalled -Helper 'Dark')) { + Write-UserMessage -Message '''dark'' is not installed! It is essential component for extraction of WiX Toolset based installers.' -Warning Write-UserMessage -Message @( ' Fixable with running following command:' ' scoop install dark' @@ -181,8 +205,8 @@ function Test-HelpersInstalled { $result = $false } - if (!(Test-HelperInstalled -Helper LessMsi)) { - Write-UserMessage -Message "'lessmsi' is not installed! It is essential component for extraction of msi installers." -Warning + if (!(Test-HelperInstalled -Helper 'LessMsi')) { + Write-UserMessage -Message '''lessmsi'' is not installed! It is essential component for extraction of msi installers.' -Warning Write-UserMessage -Message @( ' Fixable with running following command:' ' scoop install lessmsi' @@ -194,6 +218,10 @@ function Test-HelpersInstalled { } function Test-Config { + <# + .SYNOPSIS + Test if various recommended scoop configurations are set correctly. + #> [CmdletBinding()] [OutputType([bool])] param() @@ -212,6 +240,10 @@ function Test-Config { } function Test-CompletionRegistered { + <# + .SYNOPSIS + Test if native completion is imported. + #> $module = Get-Module 'Scoop-Completion' if (($null -eq $module) -or ($module.Author -notlike 'Jakub*')) { diff --git a/lib/Git.ps1 b/lib/Git.ps1 index 546e3a2f04..ff4487ecff 100644 --- a/lib/Git.ps1 +++ b/lib/Git.ps1 @@ -5,7 +5,7 @@ function Invoke-GitCmd { <# .SYNOPSIS - Git execution wrapper support -C parameter. + Git execution wrapper with -C parameter support. .PARAMETER Command Specifies git command to execute. .PARAMETER Repository diff --git a/lib/Helpers.ps1 b/lib/Helpers.ps1 index 85a276bfdc..31bb37ea1e 100644 --- a/lib/Helpers.ps1 +++ b/lib/Helpers.ps1 @@ -105,36 +105,6 @@ function Confirm-DirectoryExistence { } } -function Set-TerminatingError { - <# - .SYNOPSIS - Throw [ScoopException] helper for universal exception handling. - .DESCRIPTION - Format |- should be respected all the time as it will allow to dynamically post new issue prompts - in manifest scripts and mainly it is easy and unified way how to detect reportable problems. - Use 'Ignore|-
' If you do not want to show new issue prompt. Usually in problems not related to specific manifest - .PARAMETER Title - Specifies the exception message. - It should be in format '|-'. - .PARAMETER ID - Specifies the global identifier of the error condition. - #> - param([Alias('Message')] [String] $Title, [String] $ID = 'Scoop', [Switch] $ForceThrow) - - if (!$ForceThrow -and ($PSCmdlet -and $IsWindows)) { - $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - ([ScoopException]::new($Title)), - $ID, - [System.Management.Automation.ErrorCategory]::OpenError, - $null - ) - ) - } else { - throw [ScoopException]::new($Title) - } -} - function Stop-ScoopExecution { <# .SYNOPSIS @@ -193,7 +163,7 @@ function Out-UTF8File { ) process { if ($PSVersionTable.PSVersion.Major -ge 6) { - Set-Content -LiteralPath $File -Value $Content -Encoding utf8 + Set-Content -LiteralPath $File -Value $Content -Encoding 'utf8' } else { [System.IO.File]::WriteAllLines($File, ($Content -join "`r`n")) } @@ -245,7 +215,7 @@ function Get-MagicByte { ) process { - if (!(Test-Path $File -PathType Leaf)) { return '' } + if (!(Test-Path $File -PathType 'Leaf')) { return '' } if ((Get-Command Get-Content).Parameters.ContainsKey('AsByteStream')) { # PowerShell Core (6.0+) '-Encoding byte' is replaced by '-AsByteStream' @@ -270,9 +240,9 @@ function Get-MagicByte { } function _resetAlias($name, $value) { - $existing = Get-Alias $name -ErrorAction Ignore + $existing = Get-Alias $name -ErrorAction 'Ignore' - if ($existing -and ($existing | Where-Object -Property Options -Match 'readonly')) { + if ($existing -and ($existing | Where-Object -Property 'Options' -Match 'readonly')) { if ($existing.Definition -ne $value) { Write-UserMessage "Alias $name is read-only; cannot reset it." -Warning } @@ -289,16 +259,16 @@ function _resetAlias($name, $value) { return } - Set-Alias $name $value -Scope Script -Option AllScope + Set-Alias $name $value -Scope 'Script' -Option 'AllScope' } function Reset-Alias { # For aliases where there's a local function, re-alias so the function takes precedence - $aliases = Get-Alias | Where-Object -Property Options -NotMatch 'readonly|allscope' | Select-Object -ExpandProperty Name + $aliases = Get-Alias | Where-Object -Property 'Options' -NotMatch 'readonly|allscope' | Select-Object -ExpandProperty 'Name' Get-ChildItem Function: | ForEach-Object { $fn = $_.Name if ($fn -in $aliases) { - Set-Alias $fn Local:$fn -Scope Script + Set-Alias $fn Local:$fn -Scope 'Script' } } @@ -312,7 +282,7 @@ function Reset-Alias { 'gm' = 'Get-Member' 'iex' = 'Invoke-Expression' 'ls' = 'Get-ChildItem' - 'mkdir' = { New-Item -Type Directory @args } + 'mkdir' = { New-Item -Type 'Directory' @args } 'mv' = 'Move-Item' 'rm' = 'Remove-Item' 'sc' = 'Set-Content' @@ -345,7 +315,7 @@ function New-IssuePrompt { $url = known_bucket_repo $Bucket $bucketPath = Join-Path $SCOOP_BUCKETS_DIRECTORY $Bucket - if ((Test-Path $bucketPath) -and (Join-Path $bucketPath '.git' | Test-Path -PathType Container)) { + if ((Test-Path $bucketPath) -and (Join-Path $bucketPath '.git' | Test-Path -PathType 'Container')) { $remote = Invoke-GitCmd -Repository $bucketPath -Command 'config' -Argument '--get', 'remote.origin.url' # Support ssh and http syntax # git@PROVIDER:USER/REPO.git @@ -357,7 +327,7 @@ function New-IssuePrompt { } if (!$url) { - Write-UserMessage -Message 'Please contact the manifest maintainer!' -Color DarkRed + Write-UserMessage -Message 'Please contact the manifest maintainer!' -Color 'DarkRed' return } @@ -377,7 +347,7 @@ function New-IssuePrompt { } } - Write-UserMessage -Message "$msg`n$url" -Color DarkRed + Write-UserMessage -Message "$msg`n$url" -Color 'DarkRed' } #region Exceptions diff --git a/lib/Update.ps1 b/lib/Update.ps1 index ed266be8fa..c092e92ab2 100644 --- a/lib/Update.ps1 +++ b/lib/Update.ps1 @@ -37,7 +37,7 @@ function Update-ScoopCoreClone { if (!(Test-Path $newDir -PathType Container)) { Stop-ScoopExecution -Message 'Scoop update failed.' } # Replace non-git scoop with the git version - Remove-Item $TargetDirectory -ErrorAction Stop -Force -Recurse + Remove-Item $TargetDirectory -ErrorAction 'Stop' -Force -Recurse Move-Item $newDir $TargetDirectory } @@ -104,7 +104,7 @@ function Update-ScoopLocalBucket { $g = Join-Path $loc '.git' # Make sure main bucket, which was downloaded as zip, will be properly "converted" into git - if (($b -eq 'main') -and !(Test-Path $g -PathType Container)) { + if (($b -eq 'main') -and !(Test-Path $g -PathType 'Container')) { Remove-Bucket -Name 'main' Add-Bucket -Name 'main' } @@ -153,7 +153,7 @@ function Update-Scoop { # Clone new installation or pull changes $par = @{ 'Repo' = $configRepo; 'Branch' = $configBranch; 'TargetDirectory' = $currentDir } - if (Join-Path $currentDir '.git' | Test-Path -PathType Container) { + if (Join-Path $currentDir '.git' | Test-Path -PathType 'Container') { Update-ScoopCorePull @par } else { Update-ScoopCoreClone @par @@ -294,7 +294,7 @@ function Update-App { $dir = versiondir $App $oldVersion $Global $old = Join-Path $dir "..\_$version.old" - if (Test-Path $old -PathType Container) { + if (Test-Path $old -PathType 'Container') { $i = 1 while (Test-Path "$old($i)") { ++$i } Move-Item $dir "$old($i)" diff --git a/lib/Versions.ps1 b/lib/Versions.ps1 index b4b9888a93..a8a7396077 100644 --- a/lib/Versions.ps1 +++ b/lib/Versions.ps1 @@ -7,9 +7,9 @@ function Get-LatestVersion { .SYNOPSIS Gets the latest version of app from manifest. .PARAMETER AppName - Specifies application's name. + Specifies the application's name. .PARAMETER Bucket - Specifies bucket which the app belongs to. + Specifies the bucket which the app belongs to. .PARAMETER Uri Specifies remote app manifest's URI. #> @@ -33,7 +33,7 @@ function Get-InstalledVersion { .SYNOPSIS Gets all installed version of app, by checking version directories' 'scoop-install.json' .PARAMETER AppName - Specifies application's name. + Specifies the application's name. .PARAMETER Global Specifies globally installed application. .NOTES @@ -43,7 +43,7 @@ function Get-InstalledVersion { [CmdletBinding()] [OutputType([Object[]])] param ( - [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [Parameter(Mandatory, Position = 0, ValueFromPipeline)] [Alias('App')] [String] $AppName, [Parameter(Position = 1)] @@ -54,7 +54,7 @@ function Get-InstalledVersion { $appPath = appdir $AppName $Global $result = @() - if (Test-Path $appPath -PathType Container) { + if (Test-Path $appPath -PathType 'Container') { # TODO: Keep only scoop-install.json $arr = @((Get-ChildItem "$appPath\*\install.json"), (Get-ChildItem "$appPath\*\scoop-install.json")) $versions = @(($arr | Sort-Object -Property LastWriteTimeUtc).Directory.Name) | Where-Object { $_ -ne 'current' } @@ -70,7 +70,7 @@ function Select-CurrentVersion { .SYNOPSIS Select current version of installed app, from 'current\manifest.json' or modified time of version directory .PARAMETER AppName - Specifies application's name. + Specifies the application's name. .PARAMETER Global Specifies globally installed application. #> @@ -88,7 +88,7 @@ function Select-CurrentVersion { $appPath = appdir $AppName $Global $currentPath = Join-Path $appPath 'current' - if (Test-Path $currentPath -PathType Container) { + if (Test-Path $currentPath -PathType 'Container') { $currentVersion = (installed_manifest $AppName 'current' $Global).version # Get version from link target in case of nightly if ($currentVersion -eq 'nightly') { $currentVersion = ((Get-Item $currentPath).Target | Get-Item).BaseName } @@ -106,7 +106,7 @@ function Compare-Version { .SYNOPSIS Compares versions, mainly according to SemVer's rules. .PARAMETER ReferenceVersion - Specifies a version used as a reference for comparison. + Specifies the version used as a reference for comparison. .PARAMETER DifferenceVersion Specifies the version that are compared to the reference version. .PARAMETER Delimiter @@ -195,7 +195,7 @@ function Split-Version { .SYNOPSIS Splits version by Delimiter, convert number string to number, and separate letters from numbers. .PARAMETER Version - Specifies a version to be splitted. + Specifies the version to be splitted. .PARAMETER Delimiter Specifies the delimiter of version (Literal). #> diff --git a/lib/buckets.ps1 b/lib/buckets.ps1 index c46e404056..7ac9f36c55 100644 --- a/lib/buckets.ps1 +++ b/lib/buckets.ps1 @@ -37,7 +37,7 @@ function Find-BucketDirectory { function Get-LocalBucket { <# .SYNOPSIS - List all local buckets. + List all local bucket names. #> return (Get-ChildItem -Directory $SCOOP_BUCKETS_DIRECTORY).Name diff --git a/lib/core.ps1 b/lib/core.ps1 index f48c9d22cc..51ddfe9e42 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -39,7 +39,7 @@ function Optimize-SecurityProtocol { } } -function Get-UserAgent() { +function Get-UserAgent { return "Scoop/1.0 (+http://scoop.sh/) PowerShell/$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor) (Windows NT $([System.Environment]::OSVersion.Version.Major).$([System.Environment]::OSVersion.Version.Minor); $(if($env:PROCESSOR_ARCHITECTURE -eq 'AMD64'){'Win64; x64; '})$(if($env:PROCESSOR_ARCHITEW6432 -eq 'AMD64'){'WOW64; '})$PSEdition)" } @@ -48,22 +48,21 @@ function Show-DeprecatedWarning { .SYNOPSIS Print deprecated warning for functions, which will be deleted in near future. .PARAMETER Invocation - Invocation to identify location of line. - Just pass $MyInvocation. + $MyInvocation .PARAMETER New Specifies new command name. #> param($Invocation, [String] $New) Write-UserMessage -Message ('"{0}" will be deprecated. Please change your code/manifest to use "{1}"' -f $Invocation.MyCommand.Name, $New) -Warning - Write-UserMessage -Message " -> $($Invocation.PSCommandPath):$($Invocation.ScriptLineNumber):$($Invocation.OffsetInLine)" -Color DarkGray + Write-UserMessage -Message " -> $($Invocation.PSCommandPath):$($Invocation.ScriptLineNumber):$($Invocation.OffsetInLine)" -Color 'DarkGray' } function load_cfg($file) { if (!(Test-Path $file)) { return $null } try { - return (Get-Content $file -Raw | ConvertFrom-Json -ErrorAction Stop) + return (Get-Content $file -Raw | ConvertFrom-Json -ErrorAction 'Stop') } catch { Write-UserMessage -Message "loading ${file}: $($_.Exception.Message)" -Err } @@ -79,13 +78,13 @@ function set_config($name, $value) { if ($null -eq $SCOOP_CONFIGURATION -or $SCOOP_CONFIGURATION.Count -eq 0) { Split-Path -Path $SCOOP_CONFIGURATION_FILE | ensure | Out-Null $SCOOP_CONFIGURATION = New-Object PSObject - $SCOOP_CONFIGURATION | Add-Member -MemberType NoteProperty -Name $name -Value $value + $SCOOP_CONFIGURATION | 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 $SCOOP_CONFIGURATION.$name) { - $SCOOP_CONFIGURATION | Add-Member -MemberType NoteProperty -Name $name -Value $value + $SCOOP_CONFIGURATION | Add-Member -MemberType 'NoteProperty' -Name $name -Value $value } else { $SCOOP_CONFIGURATION.$name = $value } @@ -143,12 +142,16 @@ function is_admin { # messages function abort($msg, [int] $exit_code = 3) { Write-UserMessage -Message $msg -Err; exit $exit_code } -function error($msg) { Write-Host "ERROR $msg" -ForegroundColor DarkRed } -function warn($msg) { Write-Host "WARN $msg" -ForegroundColor DarkYellow } -function info($msg) { Write-Host "INFO $msg" -ForegroundColor DarkGray } +function error($msg) { Write-Host "ERROR $msg" -ForegroundColor 'DarkRed' } +function warn($msg) { Write-Host "WARN $msg" -ForegroundColor 'DarkYellow' } +function info($msg) { Write-Host "INFO $msg" -ForegroundColor 'DarkGray' } function message($msg) { Write-Host "$msg" } function Test-ScoopDebugEnabled { + <# + .SYNOPSIS + Load debug information from $env:SCOOP_DEBUG or from config file. + #> [CmdletBinding()] [OutputType([bool])] param() @@ -161,6 +164,12 @@ function Test-ScoopDebugEnabled { } function debug($obj) { + <# + .SYNOPSIS + Output objects in specific format to help identifying problems. + .PARAMETER obj + Specifies object/variable to be shown. + #> if (!(Test-ScoopDebugEnabled)) { return } $prefix = "DEBUG[$(Get-Date -UFormat %s)]" @@ -168,26 +177,26 @@ function debug($obj) { $msg = $obj | Out-String -Stream if ($null -eq $obj -or $null -eq $msg) { - Write-Host "$prefix $param = " -f DarkCyan -NoNewline - Write-Host '$null' -f DarkYellow -NoNewline - Write-Host " -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)" -f DarkGray + Write-Host "$prefix $param = " -ForegroundColor 'DarkCyan' -NoNewline + Write-Host '$null' -ForegroundColor 'DarkYellow' -NoNewline + Write-Host " -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)" -ForegroundColor 'DarkGray' return } if ($msg.GetType() -eq [System.Object[]]) { - Write-Host "$prefix $param ($($obj.GetType()))" -ForegroundColor DarkCyan -NoNewline - Write-Host " -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)" -ForegroundColor DarkGray + Write-Host "$prefix $param ($($obj.GetType()))" -ForegroundColor 'DarkCyan' -NoNewline + Write-Host " -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)" -ForegroundColor 'DarkGray' $msg | Where-Object { ![String]::IsNullOrWhiteSpace($_) } | Select-Object -Skip 2 | # Skip headers ForEach-Object { - Write-Host "$prefix $param.$($_)" -ForegroundColor DarkCyan + Write-Host "$prefix $param.$($_)" -ForegroundColor 'DarkCyan' } } else { - Write-Host "$prefix $param = $($msg.Trim())" -ForegroundColor DarkCyan -NoNewline - Write-Host " -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)" -f DarkGray + Write-Host "$prefix $param = $($msg.Trim())" -ForegroundColor 'DarkCyan' -NoNewline + Write-Host " -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)" -ForegroundColor 'DarkGray' } } -function success($msg) { Write-Host $msg -ForegroundColor DarkGreen } +function success($msg) { Write-Host $msg -ForegroundColor 'DarkGreen' } function filesize($length) { $gb = [System.Math]::Pow(2, 30) @@ -232,44 +241,65 @@ function installed($app, $global = $null) { } function installed_apps($global) { $dir = appsdir $global - if (Test-Path $dir) { Get-ChildItem $dir -Exclude 'scoop' -Directory | Select-Object -ExpandProperty Name } + if (Test-Path $dir) { Get-ChildItem $dir -Exclude 'scoop' -Directory | Select-Object -ExpandProperty 'Name' } } function Get-AppFilePath { + <# + .SYNOPSIS + Get full path to the specific executable under specific application installed via scoop. + .PARAMETER App + Specifies the scoop's application name. + .PARAMETER File + Specifies the executable name. + #> [CmdletBinding()] [OutputType([String])] param( - [Parameter(Mandatory, Position = 0)] + [Parameter(Mandatory)] [String] $App, - [Parameter(Mandatory, Position = 1)] + [Parameter(Mandatory)] [String] $File ) + # TODO: Support NO_JUNCTION # Normal path to file - $Path = versiondir $App 'current' $false | Join-Path -ChildPath $File - if (Test-Path $Path) { return $Path } + $path = versiondir $App 'current' $false | Join-Path -ChildPath $File + if (Test-Path $path) { return $path } # Global path to file - $Path = versiondir $App 'current' $true | Join-Path -ChildPath $File - if (Test-Path $Path) { return $Path } + $path = versiondir $App 'current' $true | Join-Path -ChildPath $File + if (Test-Path $path) { return $path } # Not found return $null } function Test-CommandAvailable { + <# + .SYNOPSIS + Test if command is available in PATH. + .PARAMETER Name + Specifies the command name. + #> [CmdletBinding()] [OutputType([bool])] param ([Parameter(Mandatory, ValueFromPipeline)] [Alias('Command')] [String] $Name) - process { return [bool] (Get-Command $Name -ErrorAction Ignore) } + process { return [bool] (Get-Command $Name -ErrorAction 'Ignore') } } function Get-HelperPath { + <# + .SYNOPSIS + Get full path to the often used application's executables. + .PARAMETER Helper + Specifies the name of helper application. + #> [CmdletBinding()] [OutputType([String])] param( - [Parameter(Mandatory, Position = 0, ValueFromPipeline)] + [Parameter(Mandatory, ValueFromPipeline)] [ValidateSet('7zip', 'Lessmsi', 'Innounp', 'Dark', 'Aria2')] [String] $Helper ) @@ -299,10 +329,16 @@ function Get-HelperPath { } function Test-HelperInstalled { + <# + .SYNOPSIS + Test if specified widely used application is installed. + .PARAMETER Helper + Specifies the name of application. + #> [CmdletBinding()] [OutputType([bool])] param( - [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [Parameter(Mandatory, ValueFromPipeline)] [ValidateSet('7zip', 'Lessmsi', 'Innounp', 'Dark', 'Aria2')] [String] $Helper ) @@ -311,7 +347,15 @@ function Test-HelperInstalled { } function Test-Aria2Enabled { - return (Test-HelperInstalled -Helper Aria2) -and (get_config 'aria2-enabled' $true) + <# + .SYNOPSIS + Test if aria2 application is installed and enabled. + #> + [CmdletBinding()] + [OutputType([bool])] + param() + + process { return (Test-HelperInstalled -Helper 'Aria2') -and (get_config 'aria2-enabled' $true) } } function app_status($app, $global) { @@ -423,6 +467,22 @@ function is_local($path) { return ($path -notmatch '^https?://') -and (Test-Path # operations function Invoke-ExternalCommand { + <# + .SYNOPSIS + Run command using System.Diagnostics.Process with support for logs. + .PARAMETER FilePath + Specifies the path to the executable. + .PARAMETER ArgumentList + Specifies the array of arguments to be passed to the executable. + .PARAMETER RunAs + Specifies to use 'runas' to use elevated privileges. + .PARAMETER Activity + Specifies to use verbose output to user. + .PARAMETER ContinueExitCodes + Specifies key/value pair of allowed non-zero exit codes and description for them. + .PARAMETER LogPath + Specifies the path where log file should be saved. + #> [CmdletBinding(DefaultParameterSetName = 'Default')] [OutputType([bool])] param ( @@ -449,6 +509,7 @@ function Invoke-ExternalCommand { $Process.StartInfo.FileName = $FilePath $Process.StartInfo.Arguments = ($ArgumentList | Select-Object -Unique) -join ' ' $Process.StartInfo.UseShellExecute = $false + if ($LogPath) { if ($FilePath -match '(^|\W)msiexec($|\W)') { $Process.StartInfo.Arguments += " /lwe `"$LogPath`"" @@ -457,35 +518,40 @@ function Invoke-ExternalCommand { $Process.StartInfo.RedirectStandardError = $true } } + if ($RunAs) { $Process.StartInfo.UseShellExecute = $true $Process.StartInfo.Verb = 'RunAs' } + try { $Process.Start() | Out-Null } catch { - if ($Activity) { Write-UserMessage -Message 'error.' -Color DarkRed } + if ($Activity) { Write-UserMessage -Message 'error.' -Color 'DarkRed' } Write-UserMessage -Message $_.Exception.Message -Err return $false } + if ($LogPath -and ($FilePath -notmatch '(^|\W)msiexec($|\W)')) { - Out-File -FilePath $LogPath -Encoding ASCII -Append -InputObject $Process.StandardOutput.ReadToEnd() + Out-File -InputObject $Process.StandardOutput.ReadToEnd() -FilePath $LogPath -Encoding 'ASCII' -Append } + $Process.WaitForExit() + if ($Process.ExitCode -ne 0) { if ($ContinueExitCodes -and ($ContinueExitCodes.ContainsKey($Process.ExitCode))) { if ($Activity) { - Write-Host 'done.' -ForegroundColor DarkYellow + Write-Host 'done.' -ForegroundColor 'DarkYellow' } Write-UserMessage -Message $ContinueExitCodes[$Process.ExitCode] -Warning return $true } else { - if ($Activity) { Write-UserMessage -Message 'error.' -Color DarkRed } + if ($Activity) { Write-UserMessage -Message 'error.' -Color 'DarkRed' } Write-UserMessage -Message "Exit code was $($Process.ExitCode)!" -Err return $false } } - if ($Activity) { Write-Host 'done.' -ForegroundColor Green } + if ($Activity) { Write-Host 'done.' -ForegroundColor 'Green' } return $true } @@ -612,9 +678,9 @@ function shim($path, $global, $name, $arg) { if ($path -match '\.jar$') { "if(`$MyInvocation.ExpectingInput) { `$input | & java -jar `$path $arg @args } else { & java -jar `$path $arg @args }" | Out-File "$shim.ps1" -Encoding utf8 -Append } else { - "if(`$MyInvocation.ExpectingInput) { `$input | & `$path $arg @args } else { & `$path $arg @args }" | Out-File "$shim.ps1" -Encoding utf8 -Append + "if(`$MyInvocation.ExpectingInput) { `$input | & `$path $arg @args } else { & `$path $arg @args }" | Out-File "$shim.ps1" -Encoding 'utf8' -Append } - Add-Content "$shim.ps1" 'exit $LASTEXITCODE' -Encoding utf8 + Add-Content "$shim.ps1" 'exit $LASTEXITCODE' -Encoding 'utf8' #endregion PS1 shim if ($path -match '\.(exe|com)$') { @@ -640,19 +706,19 @@ set args=%args:(=``(% set args=%args:)=``)% set invalid=`"=' if !args! == !invalid! ( set args= ) -powershell -noprofile -ex unrestricted `"& '$resolved_path' $arg %args%;exit `$LASTEXITCODE`"" | Out-File "$shim.cmd" -Encoding Ascii +powershell -noprofile -ex unrestricted `"& '$resolved_path' $arg %args%;exit `$LASTEXITCODE`"" | Out-File "$shim.cmd" -Encoding 'Ascii' - "#!/bin/sh`npowershell.exe -noprofile -ex unrestricted `"& '$resolved_path'`" $arg `"$@`"" | Out-File $shim -Encoding Ascii + "#!/bin/sh`npowershell.exe -noprofile -ex unrestricted `"& '$resolved_path'`" $arg `"$@`"" | Out-File $shim -Encoding 'Ascii' } elseif ($path -match '\.jar$') { - "@java -jar `"$resolved_path`" $arg %*" | Out-File "$shim.cmd" -Encoding Ascii - "#!/bin/sh`njava -jar `"$resolved_path`" $arg `"$@`"" | Out-File $shim -Encoding Ascii + "@java -jar `"$resolved_path`" $arg %*" | Out-File "$shim.cmd" -Encoding 'Ascii' + "#!/bin/sh`njava -jar `"$resolved_path`" $arg `"$@`"" | Out-File $shim -Encoding 'Ascii' } } function search_in_path($target) { $path = (env 'PATH' $false) + ';' + (env 'PATH' $true) foreach ($dir in $path.Split(';')) { - if (Test-Path "$dir\$target" -PathType Leaf) { + if (Test-Path "$dir\$target" -PathType 'Leaf') { return Join-Path $dir $target } } @@ -681,6 +747,15 @@ function ensure_architecture($architecture_opt) { } function Confirm-InstallationStatus { + <# + .SYNOPSIS + Get status of specific applications. + Returns array of 3 item arrays (appliation name, globally installed, bucket name) + .PARAMETER Apps + Specifies the array of applications to be evalueated. + .PARAMETER Global + Specifies to check globally installed applications. + #> [CmdletBinding()] param( [Parameter(Mandatory)] @@ -688,32 +763,33 @@ function Confirm-InstallationStatus { [Switch] $Global ) $Global | Out-Null # PowerShell/PSScriptAnalyzer#1472 - $Installed = @() - $Apps | Select-Object -Unique | Where-Object { $_.Name -ne 'scoop' } | ForEach-Object { - $App, $null, $null = parse_app $_ - $buc = (app_status $App $Global).bucket + $installed = @() + + $Apps | Select-Object -Unique | Where-Object -Property 'Name' -NE -Value 'scoop' | ForEach-Object { + $app, $null, $null = parse_app $_ + $buc = (app_status $app $Global).bucket if ($Global) { - if (installed $App $true) { - $Installed += , @($App, $true, $buc) - } elseif (installed $App $false) { - Write-UserMessage -Message "'$App' isn't installed globally, but it is installed for your account." -Err + if (installed $app $true) { + $installed += , @($app, $true, $buc) + } elseif (installed $app $false) { + Write-UserMessage -Message "'$app' isn't installed globally, but it is installed for your account." -Err Write-UserMessage -Message 'Try again without the --global (or -g) flag instead.' -Warning } else { - Write-UserMessage -Message "'$App' isn't installed." -Err + Write-UserMessage -Message "'$app' isn't installed." -Err } } else { - if (installed $App $false) { - $Installed += , @($App, $false, $buc) - } elseif (installed $App $true) { - Write-UserMessage -Message "'$App' isn't installed for your account, but it is installed globally." -Err + if (installed $app $false) { + $installed += , @($app, $false, $buc) + } elseif (installed $app $true) { + Write-UserMessage -Message "'$app' isn't installed for your account, but it is installed globally." -Err Write-UserMessage -Message 'Try again with the --global (or -g) flag instead.' -Warning } else { - Write-UserMessage -Message "'$App' isn't installed." -Err + Write-UserMessage -Message "'$app' isn't installed." -Err } } } - return , $Installed + return , $installed } function strip_path($orig_path, $dir) { diff --git a/lib/decompress.ps1 b/lib/decompress.ps1 index 05a92f1aaf..b718d13b7f 100644 --- a/lib/decompress.ps1 +++ b/lib/decompress.ps1 @@ -5,6 +5,14 @@ #region helpers function Test-7zipRequirement { + <# + .SYNOPSIS + Test if file or url requires 7zip to be installed. + .PARAMETER URL + Specifies the string representing URL. + .PARAMETER File + Specifies the filename. + #> [CmdletBinding(DefaultParameterSetName = 'URL')] [OutputType([Boolean])] param ( @@ -17,7 +25,6 @@ function Test-7zipRequirement { if (!$File -and ($null -eq $URL)) { return $false } - if ($URL) { # For dependencies resolving if (get_config '7ZIPEXTRACT_USE_EXTERNAL' $false) { @@ -31,6 +38,14 @@ function Test-7zipRequirement { } function Test-LessmsiRequirement { + <# + .SYNOPSIS + Test if file or url requires lessmsi to be installed. + .PARAMETER URL + Specifies the string representing URL. + .PARAMETER File + Specifies the filename. + #> [CmdletBinding()] [OutputType([Boolean])] param ( @@ -50,6 +65,22 @@ function Test-LessmsiRequirement { #endregion helpers function Expand-7zipArchive { + <# + .SYNOPSIS + Extract files from 7zip archive. + .PARAMETER Path + Specifies the path to the archive. + .PARAMETER DestinationPath + Specifies the location, where archive should be extracted. + .PARAMETER ExtractDir + Specifies to extract only nested directory inside archive. + .PARAMETER Switches + Specifies additional parameters passed to the extraction. + .PARAMETER Overwrite + Specifies how files with same names inside archive are handled. + .PARAMETER Removal + Specifies to remove the archive after extraction is done. + #> [CmdletBinding()] param ( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] @@ -67,7 +98,7 @@ function Expand-7zipArchive { begin { if (get_config '7ZIPEXTRACT_USE_EXTERNAL' $false) { try { - $7zPath = (Get-Command '7z' -CommandType Application | Select-Object -First 1).Source + $7zPath = (Get-Command '7z' -CommandType 'Application' | Select-Object -First 1).Source } catch [System.Management.Automation.CommandNotFoundException] { throw [ScoopException] "Cannot find external 7-Zip (7z.exe) while '7ZIPEXTRACT_USE_EXTERNAL' is 'true'!`nRun 'scoop config 7ZIPEXTRACT_USE_EXTERNAL false' or install 7zip manually and try again." # TerminatingError thrown } @@ -122,6 +153,20 @@ function Expand-7zipArchive { } function Expand-MsiArchive { + <# + .SYNOPSIS + Extract files from msi files. + .PARAMETER Path + Specifies the path to the file. + .PARAMETER DestinationPath + Specifies the location, where file should be extracted. + .PARAMETER ExtractDir + Specifies to extract only nested directory inside file. + .PARAMETER Switches + Specifies additional parameters passed to the extraction. + .PARAMETER Removal + Specifies to remove the file after extraction is done. + #> [CmdletBinding()] param ( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] @@ -181,6 +226,20 @@ function Expand-MsiArchive { } function Expand-InnoArchive { + <# + .SYNOPSIS + Extract files from innosetup file. + .PARAMETER Path + Specifies the path to the file. + .PARAMETER DestinationPath + Specifies the location, where file should be extracted. + .PARAMETER ExtractDir + Specifies to extract only nested directory inside file. + .PARAMETER Switches + Specifies additional parameters passed to the extraction. + .PARAMETER Removal + Specifies to remove the file after extraction is done. + #> [CmdletBinding()] param ( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] @@ -222,6 +281,18 @@ function Expand-InnoArchive { } function Expand-ZipArchive { + <# + .SYNOPSIS + Extract files from zip archive. + .PARAMETER Path + Specifies the path to the archive. + .PARAMETER DestinationPath + Specifies the location, where archive should be extracted. + .PARAMETER ExtractDir + Specifies to extract only nested directory inside archive. + .PARAMETER Removal + Specifies to remove the archive after extraction is done. + #> [CmdletBinding()] param ( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] @@ -277,6 +348,18 @@ function Expand-ZipArchive { } function Expand-DarkArchive { + <# + .SYNOPSIS + Extract files from dark installers. + .PARAMETER Path + Specifies the path to the dark installer. + .PARAMETER DestinationPath + Specifies the location, where installer should be extracted. + .PARAMETER Switches + Specifies additional parameters passed to the extraction. + .PARAMETER Removal + Specifies to remove the installer after extraction is done. + #> [CmdletBinding()] param ( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] diff --git a/lib/description.ps1 b/lib/description.ps1 index 00a296c5b4..bce4dc9c5e 100644 --- a/lib/description.ps1 +++ b/lib/description.ps1 @@ -18,7 +18,7 @@ function find_description($url, $html, $redir = $false) { if ($refresh -and !$redir) { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $html = $wc.downloadstring($refresh) + $html = $wc.DownloadString($refresh) return find_description $refresh $html $true } @@ -50,9 +50,9 @@ function clean_description($description) { # Collects meta tags from $html into hashtables. function meta_tags($html) { $tags = @() - $meta = ([System.Text.RegularExpressions.Regex] ']+>').matches($html) + $meta = ([System.Text.RegularExpressions.Regex] ']+>').Matches($html) $meta | ForEach-Object { - $attrs = ([System.Text.RegularExpressions.Regex] '([\w-]+)="([^"]+)"').matches($_.Value) + $attrs = ([System.Text.RegularExpressions.Regex] '([\w-]+)="([^"]+)"').Matches($_.Value) $hash = @{ } $attrs | ForEach-Object { $hash[$_.Groups[1].value] = $_.Groups[2].Value @@ -111,15 +111,15 @@ function strip_html($html) { if ($encoding_meta -match 'charset\s*=\s*(.*)') { $charset = $matches[1] try { - $encoding = [text.encoding]::getencoding($charset) + $encoding = [Text.Encoding]::GetEncoding($charset) } catch { Write-Warning 'Unknown charset' } if ($encoding) { - $html = ([regex]'&#(\d+);?').replace($html, { + $html = ([regex]'&#(\d+);?').Replace($html, { param($m) try { - return $encoding.getstring($m.Groups[1].Value) + return $encoding.GetString($m.Groups[1].Value) } catch { return $m.value } diff --git a/lib/help.ps1 b/lib/help.ps1 index cdba88a082..23d23b553d 100644 --- a/lib/help.ps1 +++ b/lib/help.ps1 @@ -37,7 +37,7 @@ function print_summaries { $commands.Add("$command ", $summary) # add padding } - $commands.GetEnumerator() | Sort-Object -Property Name | Format-Table -AutoSize -HideTableHeaders -Wrap + $commands.GetEnumerator() | Sort-Object -Property 'Name' | Format-Table -AutoSize -HideTableHeaders -Wrap } function my_usage { diff --git a/lib/uninstall.ps1 b/lib/uninstall.ps1 index fd9230d5ac..d582909c15 100644 --- a/lib/uninstall.ps1 +++ b/lib/uninstall.ps1 @@ -43,7 +43,7 @@ function Uninstall-ScoopApplication { ) # Do not uninstall when there is any process opened from application directory - $processdir = appdir $App $Global | Resolve-Path | Select-Object -ExpandProperty Path + $processdir = appdir $App $Global | Resolve-Path | Select-Object -ExpandProperty 'Path' $processes = Get-Process | Where-Object { $_.Path -like "$processdir\*" } if ($processes) { $plPr = pluralize $processes.Count 'Process' 'Processes' @@ -65,7 +65,7 @@ function Uninstall-ScoopApplication { Write-UserMessage -Message "Uninstalling '$App' ($version)" -Output:$false try { - Test-Path $dir -ErrorAction Stop | Out-Null + Test-Path $dir -ErrorAction 'Stop' | Out-Null } catch [UnauthorizedAccessException] { Write-UserMessage -Message "Access denied: $dir. You might need to restart." -Err return $false @@ -96,7 +96,7 @@ function Uninstall-ScoopApplication { try { # Unlink all potential old link before doing recursive Remove-Item unlink_persist_data $dir - Remove-Item $dir -Recurse -Force -ErrorAction Stop + Remove-Item $dir -ErrorAction 'Stop' -Recurse -Force } catch { if (Test-Path $dir) { Write-UserMessage -Message "Couldn't remove '$(friendly_path $dir)'; it may be in use." -Err @@ -104,6 +104,7 @@ function Uninstall-ScoopApplication { } } + # TODO: foreach Get-InstalledVersion -AppName $App -Global:$Global | ForEach-Object { Write-UserMessage -Message "Removing older version ($_)." -Output:$false @@ -111,7 +112,7 @@ function Uninstall-ScoopApplication { try { # Unlink all potential old link before doing recursive Remove-Item unlink_persist_data $dir - Remove-Item $dir -ErrorAction Stop -Recurse -Force + Remove-Item $dir -ErrorAction 'Stop' -Recurse -Force } catch { Write-UserMessage -Message "Couldn't remove '$(friendly_path $dir)'; it may be in use." -Err return $false @@ -123,7 +124,7 @@ function Uninstall-ScoopApplication { try { # If last install failed, the directory seems to be locked and this # will throw an error about the directory not existing - Remove-Item $appdir -ErrorAction Stop -Recurse -Force + Remove-Item $appdir -ErrorAction 'Stop' -Recurse -Force } catch { if ((Test-Path $appdir)) { return $false } # only throw if the dir still exists } @@ -136,7 +137,7 @@ function Uninstall-ScoopApplication { if (Test-Path $persist_dir) { try { - Remove-Item $persist_dir -ErrorAction Stop -Recurse -Force + Remove-Item $persist_dir -ErrorAction 'Stop' -Recurse -Force } catch { Write-UserMessage -Message "Couldn't remove '$(friendly_path $persist_dir)'" -Err return $false diff --git a/libexec/scoop-alias.ps1 b/libexec/scoop-alias.ps1 index 0a86eeb093..d66dcb4b66 100644 --- a/libexec/scoop-alias.ps1 +++ b/libexec/scoop-alias.ps1 @@ -71,7 +71,7 @@ switch ($Option) { break } - if (Test-Path $path -PathType Leaf) { + if (Test-Path $path -PathType 'Leaf') { if ($Option -eq 'edit') { Start-Process $path } elseif ($Option -eq 'path') { diff --git a/libexec/scoop-cache.ps1 b/libexec/scoop-cache.ps1 index 6c32fe1f80..7d3d15480d 100644 --- a/libexec/scoop-cache.ps1 +++ b/libexec/scoop-cache.ps1 @@ -28,7 +28,7 @@ function cacheinfo($file) { } function show($app) { - $files = @(Get-ChildItem $SCOOP_CACHE_DIRECTORY | Where-Object -Property Name -Match "^$app") + $files = @(Get-ChildItem $SCOOP_CACHE_DIRECTORY | Where-Object -Property 'Name' -Match "^$app") $total_length = ($files | Measure-Object length -Sum).sum -as [double] $f_app = @{ 'Expression' = { "$($_.app) ($($_.version))" } } @@ -46,7 +46,7 @@ switch ($cmd) { 'rm' { if (!$app) { Stop-ScoopExecution -Message 'Parameter missing' -Usage (my_usage) } Join-Path $SCOOP_CACHE_DIRECTORY "$app#*" | Remove-Item -Force -Recurse - Join-Path $SCOOP_CACHE_DIRECTORY "$app.txt" | Remove-Item -ErrorAction SilentlyContinue -Force -Recurse + Join-Path $SCOOP_CACHE_DIRECTORY "$app.txt" | Remove-Item -ErrorAction 'SilentlyContinue' -Force -Recurse } 'show' { show $app diff --git a/libexec/scoop-cat.ps1 b/libexec/scoop-cat.ps1 index 7d12ae2ffa..d07a95ca1d 100644 --- a/libexec/scoop-cat.ps1 +++ b/libexec/scoop-cat.ps1 @@ -35,7 +35,7 @@ foreach ($app in $Application) { } if ($manifest) { - Write-UserMessage -Message "Showing manifest for $app" -Color Green + Write-UserMessage -Message "Showing manifest for $app" -Color 'Green' $manifest | ConvertToPrettyJson | Write-UserMessage -Output } else { diff --git a/libexec/scoop-cleanup.ps1 b/libexec/scoop-cleanup.ps1 index f6434b3a3f..556c6dd00a 100644 --- a/libexec/scoop-cleanup.ps1 +++ b/libexec/scoop-cleanup.ps1 @@ -38,14 +38,14 @@ function cleanup($app, $global, $verbose, $cache) { return } - Write-Host "Removing ${app}:" -ForegroundColor Yellow -NoNewline + Write-Host "Removing ${app}:" -ForegroundColor 'Yellow' -NoNewline $versions | ForEach-Object { $version = $_ Write-Host " $version" -NoNewline $dir = versiondir $app $version $global # unlink all potential old link before doing recursive Remove-Item unlink_persist_data $dir - Remove-Item $dir -ErrorAction Stop -Recurse -Force + Remove-Item $dir -ErrorAction 'Stop' -Recurse -Force } Write-Host '' } @@ -74,7 +74,7 @@ if ($apps) { } } - if ($cache) { Join-Path $SCOOP_CACHE_DIRECTORY '*.download' | Remove-Item -ErrorAction Ignore } + if ($cache) { Join-Path $SCOOP_CACHE_DIRECTORY '*.download' | Remove-Item -ErrorAction 'Ignore' } if (!$verbose) { Write-UserMessage -Message 'Everything is shiny now!' -Success } } diff --git a/libexec/scoop-download.ps1 b/libexec/scoop-download.ps1 index a8c2bc2219..10b4217b3e 100644 --- a/libexec/scoop-download.ps1 +++ b/libexec/scoop-download.ps1 @@ -77,7 +77,7 @@ foreach ($app in $application) { $checkHash = $false } - Write-UserMessage "Starting download for $app" -Color Green + Write-UserMessage "Starting download for $app" -Color 'Green' $registered = $false # TODO: Rework with proper wrappers after #3149 diff --git a/libexec/scoop-export.ps1 b/libexec/scoop-export.ps1 index dbe4f92e92..ff88d3fff2 100644 --- a/libexec/scoop-export.ps1 +++ b/libexec/scoop-export.ps1 @@ -17,7 +17,7 @@ $global = installed_apps $true | ForEach-Object { @{ 'name' = $_; 'global' = $tr $apps = @($local) + @($global) if ($apps) { - $apps | Sort-Object { $_.Name } | ForEach-Object { + $apps | Sort-Object -Property 'Name' | ForEach-Object { $app = $_.name $global = $_.global $ver = Select-CurrentVersion -AppName $app -Global:$global diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index e6091dadb0..740c1204c9 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -136,7 +136,7 @@ if ($env_set -or $env_add_path) { } if ($env_set) { - $env_set | Get-Member -MemberType NoteProperty | ForEach-Object { + $env_set | Get-Member -MemberType 'NoteProperty' | ForEach-Object { $value = env $_.name $global if (!$value) { $value = format $env_set.$($_.name) @{ 'dir' = $dir } diff --git a/libexec/scoop-list.ps1 b/libexec/scoop-list.ps1 index 3d81cef3c7..498e1131ff 100644 --- a/libexec/scoop-list.ps1 +++ b/libexec/scoop-list.ps1 @@ -54,21 +54,21 @@ if ($apps) { $install_info = install_info $app $ver $global Write-Host " $app " -NoNewline - Write-Host -f DarkCyan $ver -NoNewline + Write-Host $ver -ForegroundColor 'DarkCyan' -NoNewline - if ($global) { Write-Host -f DarkGreen ' *global*' -NoNewline } + if ($global) { Write-Host ' *global*' -ForegroundColor 'DarkGreen' -NoNewline } - if (!$install_info) { Write-Host ' *failed*' -ForegroundColor DarkRed -NoNewline } - if ($install_info.hold) { Write-Host ' *hold*' -ForegroundColor DarkMagenta -NoNewline } + if (!$install_info) { Write-Host ' *failed*' -ForegroundColor 'DarkRed' -NoNewline } + if ($install_info.hold) { Write-Host ' *hold*' -ForegroundColor 'DarkMagenta' -NoNewline } if ($install_info.bucket) { - Write-Host -f Yellow " [$($install_info.bucket)]" -NoNewline + Write-Host " [$($install_info.bucket)]" -ForegroundColor 'Yellow' -NoNewline } elseif ($install_info.url) { - Write-Host -f Yellow " [$($install_info.url)]" -NoNewline + Write-Host " [$($install_info.url)]" -ForegroundColor 'Yellow' -NoNewline } if ($install_info.architecture -and $def_arch -ne $install_info.architecture) { - Write-Host -f DarkRed " {$($install_info.architecture)}" -NoNewline + Write-Host " {$($install_info.architecture)}" -ForegroundColor 'DarkRed' -NoNewline } Write-Host '' } diff --git a/libexec/scoop-reset.ps1 b/libexec/scoop-reset.ps1 index 46b772dc57..f0b4c52adb 100644 --- a/libexec/scoop-reset.ps1 +++ b/libexec/scoop-reset.ps1 @@ -31,7 +31,7 @@ foreach ($a in $apps) { $app, $bucket, $version = parse_app $app # Skip scoop - if ($app -eq 'scoop') { return } + if ($app -eq 'scoop') { continue } # Set global flag when running reset command on specific app if (($null -eq $global) -and (installed $app $true)) { $global = $true } diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index ee0bf22124..68d77e70a0 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -39,11 +39,11 @@ foreach ($bucket in (Get-LocalBucket)) { $localResults += $result foreach ($res in $result) { - Write-Host "$bucket" -NoNewline -ForegroundColor Yellow + Write-Host "$bucket" -ForegroundColor 'Yellow' -NoNewline Write-Host '/' -NoNewline - Write-Host $res.name -ForegroundColor Green + Write-Host $res.name -ForegroundColor 'Green' Write-Host ' Version: ' -NoNewline - Write-Host $res.version -ForegroundColor DarkCyan + Write-Host $res.version -ForegroundColor 'DarkCyan' $toPrint = @() if ($res.description) { $toPrint += " Description: $($res.description)" } diff --git a/libexec/scoop-status.ps1 b/libexec/scoop-status.ps1 index 9ac42b4c05..80bce68156 100644 --- a/libexec/scoop-status.ps1 +++ b/libexec/scoop-status.ps1 @@ -14,7 +14,7 @@ Reset-Alias $currentdir = versiondir 'scoop' 'current' $needs_update = $false -if (Join-Path $currentdir '.git' | Test-Path -PathType Container) { +if (Join-Path $currentdir '.git' | Test-Path -PathType 'Container') { $target = @{ 'Repository' = $currentdir } Invoke-GitCmd @target -Command 'fetch' -Argument '--quiet', 'origin' -Proxy @@ -43,7 +43,7 @@ foreach ($global in ($true, $false)) { $dir = appsdir $global if (!(Test-Path $dir)) { continue } - foreach ($application in (Get-ChildItem $dir | Where-Object -Property Name -NE -Value 'scoop')) { + foreach ($application in (Get-ChildItem $dir | Where-Object -Property 'Name' -NE -Value 'scoop')) { $app = $application.name $status = app_status $app $global if ($status.failed) { @@ -66,7 +66,7 @@ foreach ($global in ($true, $false)) { if ($outdated) { $exitCode = 3 - Write-UserMessage -Message 'Updates are available for:' -Color DarkCyan + Write-UserMessage -Message 'Updates are available for:' -Color 'DarkCyan' $outdated.keys | ForEach-Object { $versions = $outdated.$_ " ${_}: $($versions[0]) -> $($versions[1])" @@ -74,7 +74,7 @@ if ($outdated) { } if ($onhold) { - Write-UserMessage -Message 'These apps are outdated and on hold:' -Color DarkCyan + Write-UserMessage -Message 'These apps are outdated and on hold:' -Color 'DarkCyan' $onhold.keys | ForEach-Object { $versions = $onhold.$_ " ${_}: $($versions[0]) -> $($versions[1])" @@ -83,7 +83,7 @@ if ($onhold) { if ($removed) { $exitCode = 3 - Write-UserMessage -Message 'These app manifests have been removed:' -Color DarkCyan + Write-UserMessage -Message 'These app manifests have been removed:' -Color 'DarkCyan' $removed.keys | ForEach-Object { " $_" } @@ -91,7 +91,7 @@ if ($removed) { if ($failed) { $exitCode = 3 - Write-UserMessage 'These apps failed to install:' -Color DarkCyan + Write-UserMessage 'These apps failed to install:' -Color 'DarkCyan' $failed.keys | ForEach-Object { " $_" } @@ -99,7 +99,7 @@ if ($failed) { if ($missing_deps) { $exitCode = 3 - Write-UserMessage 'Missing runtime dependencies:' -Color DarkCyan + Write-UserMessage 'Missing runtime dependencies:' -Color 'DarkCyan' $missing_deps | ForEach-Object { $app, $deps = $_ " '$app' requires '$([String]::Join(', ', $deps))'" diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index c0386a48c6..3e85965bbb 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -65,16 +65,16 @@ if (!$apps) { Write-UserMessage -Message "${app}: $($status.version) -> $($status.latest_version)$globText" -Warning -SkipSeverity } } elseif ($applicationsParam -ne '*') { - Write-UserMessage -Message "${app}: $($status.version) (latest available version)" -Color Green + Write-UserMessage -Message "${app}: $($status.version) (latest available version)" -Color 'Green' } } $c = $outdatedApplications.Count if ($c -eq 0) { - Write-UserMessage -Message 'Latest versions for all apps are installed! For more information try ''scoop status''' -Color Green + Write-UserMessage -Message 'Latest versions for all apps are installed! For more information try ''scoop status''' -Color 'Green' } else { $a = pluralize $c 'app' 'apps' - Write-UserMessage -Message "Updating $c outdated ${a}:" -Color DarkCyan + Write-UserMessage -Message "Updating $c outdated ${a}:" -Color 'DarkCyan' } } diff --git a/libexec/scoop-which.ps1 b/libexec/scoop-which.ps1 index 3c791f6d08..830035705c 100644 --- a/libexec/scoop-which.ps1 +++ b/libexec/scoop-which.ps1 @@ -16,7 +16,7 @@ Reset-Alias if (!$command) { Stop-ScoopExecution -Message 'Parameter missing' -Usage (my_usage) } try { - $gcm = Get-Command $Command -ErrorAction Stop + $gcm = Get-Command $Command -ErrorAction 'Stop' } catch { Stop-ScoopExecution -Message "Command '$command' not found" } diff --git a/supporting/yaml.json b/supporting/yaml.json index cf80bd474b..ff6bf6b2c9 100644 --- a/supporting/yaml.json +++ b/supporting/yaml.json @@ -6,7 +6,7 @@ "url": "https://psg-prod-eastus.azureedge.net/packages/powershell-yaml.0.4.2.nupkg", "hash": "47f21c151775c2f0d8a21c86cedca3998f0bbcfd309b27977c9024f48da9787c", "pre_install": [ - "@('package', 'Tests', '_rels', '*.xml') | ForEach-Object { Remove-Item \"$dir\\$_\" -Force -Recurse }", + "Remove-AppDirItem 'package', 'Tests', '_rels', '*.xml'", "Get-ChildItem \"$dir\\*\" -Exclude '*.dll', '*.psd1', '*.ps1', '*.psm1', 'LICENSE' -File -Recurse | Remove-Item" ], "checkver": {