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

feat(scoop-status): Check bucket status, improve output #5011

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 45 additions & 67 deletions libexec/scoop-status.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $_
Expand All @@ -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
29 changes: 29 additions & 0 deletions supporting/formats/ScoopTypes.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,34 @@
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>ScoopStatusType</Name>
<ViewSelectedBy>
<TypeName>ScoopStatus</TypeName>
</ViewSelectedBy>
<TableControl>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Installed Version</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Latest Version</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Missing Dependencies</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Info</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>