From e2516b6243eb3a7fe032b4da721f7588652210f1 Mon Sep 17 00:00:00 2001 From: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> Date: Fri, 25 Feb 2022 13:06:46 +0530 Subject: [PATCH] feat(scoop-info): Revamp details and show more information (#4747) * feat(scoop-info): Introduce `verbose` flag * feat(scoop-info): Allow passing local manifest paths * feat(scoop-info): Show bucket and shortcuts * feat(scoop-info): Show dependencies and suggestions * feat(scoop-info): Show 'Updated at' and 'Updated by' * changelog * optimize git call * restore clicky-ness of homepage * simplify joining * use getopt * Update libexec/scoop-info.ps1 Co-authored-by: Hsiao-nan Cheung Co-authored-by: Hsiao-nan Cheung --- CHANGELOG.md | 1 + libexec/scoop-info.ps1 | 110 ++++++++++++++++++++++++++++------------- 2 files changed, 78 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2caff728a..9a91a57cb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - **scoop-list:** Show last-updated time [#4723](https://github.com/ScoopInstaller/Scoop/issues/4723)) - **scoop-cache:** Handle multiple apps and show detailed information ([#4738](https://github.com/ScoopInstaller/Scoop/pull/4738)) - **scoop-cat:** Use `bat` to pretty-print JSON ([#4742](https://github.com/ScoopInstaller/Scoop/pull/4742)) +- **scoop-info:** Revamp details and show more information ([#4747](https://github.com/ScoopInstaller/Scoop/pull/4747)) ### Bug Fixes diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index 4a1ad647fd..630606af8b 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -1,15 +1,20 @@ -# Usage: scoop info +# Usage: scoop info [--verbose] # Summary: Display information about an app -param($app) +# Options: +# -v, --verbose Show full paths and URLs -. "$PSScriptRoot\..\lib\depends.ps1" . "$PSScriptRoot\..\lib\help.ps1" . "$PSScriptRoot\..\lib\install.ps1" . "$PSScriptRoot\..\lib\manifest.ps1" . "$PSScriptRoot\..\lib\versions.ps1" +. "$PSScriptRoot\..\lib\getopt.ps1" reset_aliases +$opt, $app, $err = getopt $args 'v' 'verbose' +if ($err) { error "scoop info: $err"; exit 1 } +$verbose = $opt.v -or $opt.verbose + if (!$app) { my_usage; exit 1 } if ($app -match '^(ht|f)tps?://|\\\\') { @@ -25,7 +30,7 @@ if ($app -match '^(ht|f)tps?://|\\\\') { $global = installed $app $true $app, $bucket, $null = parse_app $app $status = app_status $app $global - $manifest, $bucket = find_manifest $app $bucket + $app, $manifest, $bucket, $url = Find-Manifest $app $bucket } if (!$manifest) { @@ -33,15 +38,19 @@ if (!$manifest) { } $install = install_info $app $status.version $global -$status.installed = $install.bucket -eq $bucket +$status.installed = $bucket -and $install.bucket -eq $bucket $version_output = $manifest.version if (!$manifest_file) { - $manifest_file = manifest_path $app $bucket + $manifest_file = if ($bucket) { manifest_path $app $bucket } else { $url } } -$dir = currentdir $app $global -$original_dir = versiondir $app $manifest.version $global -$persist_dir = persistdir $app $global +if ($verbose) { + $dir = currentdir $app $global + $original_dir = versiondir $app $manifest.version $global + $persist_dir = persistdir $app $global +} else { + $dir, $original_dir, $persist_dir = "", "", "" +} if ($status.installed) { $manifest_file = manifest_path $app $install.bucket @@ -60,31 +69,54 @@ if ($manifest.description) { $item.Description = $manifest.description } $item.Version = $version_output -$item.Website = $manifest.homepage +if ($bucket) { + $item.Bucket = $bucket +} +if ($manifest.homepage) { + $item.Website = $manifest.homepage.TrimEnd('/') +} # Show license if ($manifest.license) { - $license = $manifest.license - if ($manifest.license.identifier -and $manifest.license.url) { - $license = "$($manifest.license.identifier) ($($manifest.license.url))" + $item.License = if ($manifest.license.identifier -and $manifest.license.url) { + if ($verbose) { "$($manifest.license.identifier) ($($manifest.license.url))" } else { $manifest.license.identifier } } elseif ($manifest.license -match '^((ht)|f)tps?://') { - $license = "$($manifest.license)" + $manifest.license } elseif ($manifest.license -match '[|,]') { - $licurl = $manifest.license.Split("|,") | ForEach-Object {"https://spdx.org/licenses/$_.html"} - $license = "$($manifest.license) ($($licurl -join ', '))" + if ($verbose) { + "$($manifest.license) ($(($manifest.license -Split "\||," | ForEach-Object { "https://spdx.org/licenses/$_.html" }) -join ', '))" + } else { + $manifest.license + } + } else { + if ($verbose) { "$($manifest.license) (https://spdx.org/licenses/$($manifest.license).html)" } else { $manifest.license } + } +} + +if ($manifest.depends) { + $item.Dependencies = $manifest.depends -join ' | ' +} + +if (Test-Path $manifest_file) { + if (Get-Command git -ErrorAction Ignore) { + $gitinfo = (git -C (Split-Path $manifest_file) log -1 -s --format='%aD#%an' $manifest_file 2> $null) -Split '#' + } + if ($gitinfo) { + $item.'Updated at' = $gitinfo[0] | Get-Date + $item.'Updated by' = $gitinfo[1] } else { - $license = "$($manifest.license) (https://spdx.org/licenses/$($manifest.license).html)" + $item.'Updated at' = (Get-Item $manifest_file).LastWriteTime + $item.'Updated by' = (Get-Acl $manifest_file).Owner.Split('\')[-1] } - $item.License = $license } # Manifest file -$item.Manifest = $manifest_file +if ($verbose) { $item.Manifest = $manifest_file } if ($status.installed) { # Show installed versions $installed_output = @() Get-InstalledVersion -AppName $app -Global:$global | ForEach-Object { - $installed_output += versiondir $app $_ $global + $installed_output += if ($verbose) { versiondir $app $_ $global } else { "$_$(if ($global) { " *global*" })" } } $item.Installed = $installed_output -join "`n" } @@ -94,41 +126,53 @@ if ($binaries) { $binary_output = @() $binaries | ForEach-Object { if ($_ -is [System.Array]) { - $binary_output += "$($_[1]).exe" + $binary_output += "$($_[1]).$($_[0].Split('.')[-1])" } else { $binary_output += $_ } } $item.Binaries = $binary_output -join " | " } -$env_set = (arch_specific 'env_set' $manifest $install.architecture) -$env_add_path = (arch_specific 'env_add_path' $manifest $install.architecture) +$shortcuts = @(arch_specific 'shortcuts' $manifest $install.architecture) +if ($shortcuts) { + $shortcut_output = @() + $shortcuts | ForEach-Object { + $shortcut_output += $_[1] + } + $item.Shortcuts = $shortcut_output -join " | " +} +$env_set = arch_specific 'env_set' $manifest $install.architecture if ($env_set) { $env_vars = @() $env_set | Get-Member -member noteproperty | ForEach-Object { - $value = env $_.name $global - if (!$value) { - $value = format $env_set.$($_.name) @{ "dir" = $dir } - } - $env_vars += "$($_.name) = $value" + $env_vars += "$($_.name) = $(format $env_set.$($_.name) @{ "dir" = $dir })" } - $item.'Environment Variables' = $env_vars -join "`n" + $item.Environment = $env_vars -join "`n" } +$env_add_path = arch_specific 'env_add_path' $manifest $install.architecture if ($env_add_path) { $env_path = @() $env_add_path | Where-Object { $_ } | ForEach-Object { - if ($_ -eq '.') { - $env_path += $dir + $env_path += if ($_ -eq '.') { + $dir } else { - $env_path += "$dir\$_" + "$dir\$_" } } $item.'Path Added' = $env_path -join "`n" } +if ($manifest.suggest) { + $suggest_output = @() + $manifest.suggest.PSObject.Properties | ForEach-Object { + $suggest_output += $_.Value -join ' | ' + } + $item.Suggestions = $suggest_output -join ' | ' +} + if ($manifest.notes) { # Show notes - $item.Notes = (substitute $manifest.notes @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir}) -join "`n" + $item.Notes = (substitute $manifest.notes @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir }) -join "`n" } [PSCustomObject]$item