ThomasNieto / Scoop

A PowerShell module for Scoop.
MIT License
4 stars 1 forks source link

[Feature] Add some output to `Update-ScoopApp` #12

Open o-l-a-v opened 1 month ago

o-l-a-v commented 1 month ago

It'd be useful with some output other than -Verbose showing raw output from scoop 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.

o-l-a-v commented 1 month ago

One idea that might be simpler than parsing the string output from Scoop:

  1. Get output of scoop list before running scoop update
  2. Get output of scoop list after running scoop update
  3. Compare the two lists and output the differences.

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
}