From 6629331799764ab325aa2c6811022cb76334f246 Mon Sep 17 00:00:00 2001 From: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> Date: Wed, 22 Jun 2022 15:40:24 +0530 Subject: [PATCH] feat(scoop-status): Check bucket status, improve output (#5011) * feat(scoop-status): Check bucket status, improve output * Update CHANGELOG.md --- CHANGELOG.md | 1 + libexec/scoop-status.ps1 | 112 ++++++++------------ supporting/formats/ScoopTypes.Format.ps1xml | 29 +++++ 3 files changed, 75 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51b296ecd8..293e5bb5f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- **scoop-status:** Check bucket status, improve output ([#5011](https://github.com/ScoopInstaller/Scoop/issues/5011)) - **scoop-info:** Show app installed/download size ([#4886](https://github.com/ScoopInstaller/Scoop/issues/4886)) ### Bug Fixes diff --git a/libexec/scoop-status.ps1 b/libexec/scoop-status.ps1 index 878656693c..da2b634f87 100644 --- a/libexec/scoop-status.ps1 +++ b/libexec/scoop-status.ps1 @@ -7,24 +7,40 @@ # check if scoop needs updating $currentdir = fullpath $(versiondir 'scoop' 'current') $needs_update = $false +$bucket_needs_update = $false +$script:network_failure = $false +$list = @() +if (!(Get-FormatData ScoopStatus)) { + Update-FormatData "$PSScriptRoot\..\supporting\formats\ScoopTypes.Format.ps1xml" +} -if (Test-Path "$currentdir\.git") { - git_cmd -C "`"$currentdir`"" fetch -q origin - $commits = $(git -C $currentdir log "HEAD..origin/$(get_config SCOOP_BRANCH)" --oneline) - if ($commits) { $needs_update = $true } -} else { - $needs_update = $true +function Test-UpdateStatus($repopath) { + if (Test-Path "$repopath\.git") { + git_cmd -C "`"$repopath`"" fetch -q origin + $script:network_failure = 128 -eq $LASTEXITCODE + $branch = git -C $repopath branch --show-current + $commits = git -C $repopath log "HEAD..origin/$branch" --oneline + if ($commits) { return $true } + else { return $false } + } else { + return $true + } } -if ($needs_update) { - warn "Scoop is out of date. Run 'scoop update' to get the latest changes." -} else { success 'Scoop is up to date.' } +$needs_update = Test-UpdateStatus $currentdir +foreach ($bucket in Get-LocalBucket) { + if (Test-UpdateStatus (Find-BucketDirectory $bucket -Root)) { + $bucket_needs_update = $true + } +} -$failed = @() -$outdated = @() -$removed = @() -$missing_deps = @() -$onhold = @() +if ($needs_update) { + warn "Scoop out of date. Run 'scoop update' to get the latest changes." +} elseif ($bucket_needs_update) { + warn "Scoop bucket(s) out of date. Run 'scoop update' to get the latest changes." +} elseif (!$script:network_failure) { + success 'Scoop is up to date.' +} $true, $false | ForEach-Object { # local and global apps $global = $_ @@ -34,64 +50,26 @@ $true, $false | ForEach-Object { # local and global apps Get-ChildItem $dir | Where-Object name -NE 'scoop' | ForEach-Object { $app = $_.name $status = app_status $app $global - if ($status.failed) { - $failed += @{ $app = $status.version } - } - if ($status.removed) { - $removed += @{ $app = $status.version } - } - if ($status.outdated) { - $outdated += @{ $app = @($status.version, $status.latest_version) } - if ($status.hold) { - $onhold += @{ $app = @($status.version, $status.latest_version) } - } - } - if ($status.missing_deps) { - $missing_deps += , (@($app) + @($status.missing_deps)) - } - } -} - -if ($outdated) { - Write-Host -f DarkCyan 'Updates are available for:' - $outdated.keys | ForEach-Object { - $versions = $outdated.$_ - " $_`: $($versions[0]) -> $($versions[1])" - } -} - -if ($onhold) { - Write-Host -f DarkCyan 'These apps are outdated and on hold:' - $onhold.keys | ForEach-Object { - $versions = $onhold.$_ - " $_`: $($versions[0]) -> $($versions[1])" - } -} + if (!$status.outdated -and !$status.failed -and !$status.removed -and !$status.missing_deps) { return } -if ($removed) { - Write-Host -f DarkCyan 'These app manifests have been removed:' - $removed.keys | ForEach-Object { - " $_" + $item = [ordered]@{} + $item.Name = $app + $item.'Installed Version' = $status.version + $item.'Latest Version' = if ($status.outdated) { $status.latest_version } else { "" } + $item.'Missing Dependencies' = $status.missing_deps -Split ' ' -Join ' | ' + $info = $() + if ($status.failed) { $info += 'Install failed' } + if ($status.hold) { $info += 'Held package' } + if ($status.removed) { $info += 'Manifest removed' } + $item.Info = $info -join ', ' + $list += [PSCustomObject]$item } } -if ($failed) { - Write-Host -f DarkCyan 'These apps failed to install:' - $failed.keys | ForEach-Object { - " $_" - } -} - -if ($missing_deps) { - Write-Host -f DarkCyan 'Missing runtime dependencies:' - $missing_deps | ForEach-Object { - $app, $deps = $_ - " '$app' requires '$([string]::join("', '", $deps))'" - } -} - -if (!$old -and !$removed -and !$failed -and !$missing_deps -and !$needs_update) { +if ($list.Length -eq 0 -and !$needs_update -and !$bucket_needs_update -and !$script:network_failure) { success 'Everything is ok!' } +$list | Add-Member -TypeName ScoopStatus -PassThru + exit 0 diff --git a/supporting/formats/ScoopTypes.Format.ps1xml b/supporting/formats/ScoopTypes.Format.ps1xml index b2dff49d84..ba423f9553 100644 --- a/supporting/formats/ScoopTypes.Format.ps1xml +++ b/supporting/formats/ScoopTypes.Format.ps1xml @@ -60,5 +60,34 @@ + + ScoopStatusType + + ScoopStatus + + + + + + + Name + + + Installed Version + + + Latest Version + + + Missing Dependencies + + + Info + + + + + +