Open o-l-a-v opened 1 month ago
One idea that might be simpler than parsing the string output from Scoop:
scoop list
before running scoop update
scoop list
after running scoop update
Or use scoop status
to output what apps to update. Something like:
Write-Information -MessageData 'Updating buckets and Scoop first.'
$null = scoop update --quiet 6>$null
$ScoopOutdated = [PSCustomObject[]](scoop status 6>$null | Sort-Object -Property 'Name')
if ($ScoopOutdated.'Count' -le 0) {
Write-Information -MessageData 'No outdated apps.'
}
else {
# List installed app to get more info
$ScoopInstalled = [PSCustomObject[]](scoop list 6>$null | Sort-Object -Property 'Name')
# Add bucket and last updated info to outdated apps
foreach ($App in $ScoopOutdated) {
$Match = $ScoopInstalled.Where({$_.'Name' -eq $App.'Name'},'First')
$(
[ordered]@{
'Bucket' = [string] $Match.'Source'
'Last Updated' = [datetime] $Match.'Updated'
}
).GetEnumerator().ForEach{
$null = Add-Member -InputObject $App -MemberType 'NoteProperty' -Force -Name $_.'Name' -Value $_.'Value'
}
}
# Output info
Write-Information -MessageData (
$ScoopOutdated |
Select-Object -Property 'Name', 'Bucket', 'Installed Version', 'Latest Version', 'Last Updated' |
Format-Table -AutoSize |
Out-String
).Trim()
Write-Information -MessageData ('Found {0} app(s) that will be updated.' -f $ScoopOutdated.'Count'.ToString())
# Update outdated apps
foreach ($App in $ScoopOutdated) {
Write-Information -MessageData (
'{0} / {1} "{2}" from v{3} to v{4}' -f
(1+$ScoopOutdated.IndexOf($App)).ToString('0'*$ScoopOutdated.'Count'.ToString().'Length'),
$ScoopOutdated.'Count'.ToString(),
$App.'Name',
$App.'Installed Version',
$App.'Latest Version'
)
$null = scoop update $App.'Name' --quiet 6>$null
}
# Cleanup
Write-Information -MessageData 'Doing scoop cleanup'
$null = scoop cleanup --all 6>$null
}
It'd be useful with some output other than
-Verbose
showing raw output fromscoop update
.Would probably require some string parsing, as the output isn't really ment for further consumption.
Info that would be interesting: What app was updated, from what version, to what version. The dream would be to have this output as a powershell object.