Skip to content

Commit

Permalink
feat(scoop-info): Revamp details and show more information (ScoopInst…
Browse files Browse the repository at this point in the history
…aller#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 <niheaven@gmail.com>

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
  • Loading branch information
rashil2000 and niheaven authored Feb 25, 2022
1 parent 0cb6152 commit aa61f19
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
110 changes: 77 additions & 33 deletions libexec/scoop-info.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Usage: scoop info <app>
# Usage: scoop info <app> [--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?://|\\\\') {
Expand All @@ -25,23 +30,27 @@ 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) {
abort "Could not find manifest for '$(show_app $app $bucket)'."
}

$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 = "<root>", "<root>", "<root>"
}

if ($status.installed) {
$manifest_file = manifest_path $app $install.bucket
Expand All @@ -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"
}
Expand All @@ -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
Expand Down

0 comments on commit aa61f19

Please sign in to comment.