ScoopInstaller / Scoop

A command-line installer for Windows.
https://scoop.sh
Other
20.85k stars 1.39k forks source link

[Bug] "scoop -v" (SCOOP VERSION NUMBER) output isn't capturable ? #5778

Closed bionicles closed 4 months ago

bionicles commented 8 months ago

Bug Report

Current Behavior

(py310) PS C:\Users\ANON> scoop -v
Current Scoop version:
v0.3.1 - Released at 2022-11-15

'extras' bucket:
b8858b841 (HEAD -> master, origin/master, origin/HEAD) twitchdownloader: Update to version 1.53.9

'main' bucket:
e0d4894cc (HEAD -> master, origin/master, origin/HEAD) ugrep: Update to version 4.5.1

(py310) PS C:\Users\ANON> $x = & scoop -v | Out-String
Current Scoop version:
v0.3.1 - Released at 2022-11-15

'extras' bucket:

'main' bucket:

(py310) PS C:\Users\ANON> Log $x
[2024-01-06T14:54:35.0054196-05:00] b8858b841 twitchdownloader: Update to version 1.53.9
e0d4894cc ugrep: Update to version 4.5.1

(py310) PS C:\Users\ANON> $y = scoop -v | Out-String
Current Scoop version:
v0.3.1 - Released at 2022-11-15

'extras' bucket:

'main' bucket:

(py310) PS C:\Users\ANON> Log $y
[2024-01-06T14:58:31.0006848-05:00] b8858b841 twitchdownloader: Update to version 1.53.9
e0d4894cc ugrep: Update to version 4.5.

Expected Behavior

> $scoopVersion = scoop -v | Out-String
> Log $scoopVersion
[2024-01-06T14:54:35.0054196-05:00] "v0.3.1 - Released at 2022-11-15"

Additional context/output

I'm a scoop noob and dislike powershell so I probably don't know what I'm doing. However, one would imagine printing the version number to stdout would "just work"

Possible Solution

Scoop probably outputs the version info in a weird way, and just doing it the same way as the "b8858b841 twitchdownloader: Update to version 1.53.9 e0d4894cc ugrep: Update to version 4.5.1" would work

Or, it's outputting too much info and we just need a version number but we're getting a ton of output and it confuses PowerShell.

System details

Windows version: 11

OS architecture: 64bit

PowerShell version: [output of "$($PSVersionTable.PSVersion)"]

Additional software: [(optional) e.g. ConEmu, Git] $($PSVersionTable.PSVersion)

Major Minor Patch PreReleaseLabel BuildLabel


7 3 10

Scoop Configuration

{
  "last_update": "2024-01-06T14:39:48.5479968-05:00",
  "scoop_repo": "https://github.com/ScoopInstaller/Scoop",
  "scoop_branch": "master"
}
bionicles commented 8 months ago

Here's a workaround:

function Get-ScoopVersion {
    Log "Getting Scoop Version"
    # Define the path to Scoop's CHANGELOG.md
    $changelogPath = "C:\Users\$env:USERNAME\scoop\apps\scoop\current\CHANGELOG.md"

    # Read the version from CHANGELOG.md
    if (Test-Path -Path $changelogPath) {
        $pattern = '^## \[(?<version>v[\d.]+)\]'
        $content = Get-Content $changelogPath -Raw
        $match = [Regex]::Match($content, $pattern)

        if ($match.Success) {
            $version = $match.Groups["version"].Value
            Log "Scoop version: $version"
            return $version
        } else {
            Log "Scoop version not found in CHANGELOG"
        }
    } else {
        Log "CHANGELOG.md not found at $changelogPath"
    }
    return "Unknown"
}
[2024-01-06T15:24:44.2140546-05:00] Getting Scoop Version
[2024-01-06T15:24:44.2180717-05:00] Scoop version: v0.3.1
rashil2000 commented 4 months ago

PowerShell has a different concept of streams. It has multiple output streams, see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_output_streams?view=powershell-7.4.

The Scoop version output in scoop -v command gets written to the Information stream. To capture it, you can do:

image