Skip to content

Commit

Permalink
refactor(scoop-info): Use List View for output (ScoopInstaller#4741)
Browse files Browse the repository at this point in the history
* refactor(scoop-info): Use List View for output

* review comments
  • Loading branch information
rashil2000 authored Feb 17, 2022
1 parent f83fa14 commit 2651764
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 52 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- **rmdir:** Use 'Remove-Item' instead of 'rmdir' ([#4691](https://github.com/ScoopInstaller/Scoop/issues/4691))
- **COMSPEC:** Deprecate use of subshell cmd.exe ([#4692](https://github.com/ScoopInstaller/Scoop/issues/4692))
- **git:** Use 'git -C' to specify the work directory instead of 'Push-Location'/'Pop-Location' ([#4697](https://github.com/ScoopInstaller/Scoop/issues/4697))
- **scoop-info:** Use List View for output ([#4741](https://github.com/ScoopInstaller/Scoop/issues/4741))

### Builds

Expand Down
10 changes: 5 additions & 5 deletions bin/scoop.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#requires -v 3
#Requires -Version 5
param($cmd)

set-strictmode -off
Set-StrictMode -off

. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\buckets.ps1"
. (relpath '..\lib\commands')
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\buckets.ps1"
. "$PSScriptRoot\..\lib\commands.ps1"

reset_aliases

Expand Down
89 changes: 42 additions & 47 deletions libexec/scoop-info.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
# Summary: Display information about an app
param($app)

. "$psscriptroot\..\lib\buckets.ps1"
. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\depends.ps1"
. "$psscriptroot\..\lib\help.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\..\lib\manifest.ps1"
. "$psscriptroot\..\lib\versions.ps1"
. "$PSScriptRoot\..\lib\depends.ps1"
. "$PSScriptRoot\..\lib\help.ps1"
. "$PSScriptRoot\..\lib\install.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"
. "$PSScriptRoot\..\lib\versions.ps1"

reset_aliases

if(!$app) { my_usage; exit 1 }
if (!$app) { my_usage; exit 1 }

if ($app -match '^(ht|f)tps?://|\\\\') {
# check if $app is a URL or UNC path
Expand Down Expand Up @@ -45,24 +43,24 @@ $dir = currentdir $app $global
$original_dir = versiondir $app $manifest.version $global
$persist_dir = persistdir $app $global

if($status.installed) {
if ($status.installed) {
$manifest_file = manifest_path $app $install.bucket
if ($install.url) {
$manifest_file = $install.url
}
if($status.version -eq $manifest.version) {
if ($status.version -eq $manifest.version) {
$version_output = $status.version
} else {
$version_output = "$($status.version) (Update to $($manifest.version) available)"
}
}

Write-Output "Name: $app"
$item = [ordered]@{ Name = $app }
if ($manifest.description) {
Write-Output "Description: $($manifest.description)"
$item.Description = $manifest.description
}
Write-Output "Version: $version_output"
Write-Output "Website: $($manifest.homepage)"
$item.Version = $version_output
$item.Website = $manifest.homepage
# Show license
if ($manifest.license) {
$license = $manifest.license
Expand All @@ -76,66 +74,63 @@ if ($manifest.license) {
} else {
$license = "$($manifest.license) (https://spdx.org/licenses/$($manifest.license).html)"
}
Write-Output "License: $license"
$item.License = $license
}

# Manifest file
Write-Output "Manifest:`n $manifest_file"
$item.Manifest = $manifest_file

if($status.installed) {
if ($status.installed) {
# Show installed versions
Write-Output "Installed:"
$versions = Get-InstalledVersion -AppName $app -Global:$global
$versions | ForEach-Object {
$dir = versiondir $app $_ $global
if($global) { $dir += " *global*" }
Write-Output " $dir"
$installed_output = @()
Get-InstalledVersion -AppName $app -Global:$global | ForEach-Object {
$installed_output += versiondir $app $_ $global
}
} else {
Write-Output "Installed: No"
$item.Installed = $installed_output -join "`n"
}

$binaries = @(arch_specific 'bin' $manifest $install.architecture)
if($binaries) {
$binary_output = "Binaries:`n "
if ($binaries) {
$binary_output = @()
$binaries | ForEach-Object {
if($_ -is [System.Array]) {
$binary_output += " $($_[1]).exe"
if ($_ -is [System.Array]) {
$binary_output += "$($_[1]).exe"
} else {
$binary_output += " $_"
$binary_output += $_
}
}
Write-Output $binary_output
$item.Binaries = $binary_output -join "`n"
}
$env_set = (arch_specific 'env_set' $manifest $install.architecture)
$env_add_path = (arch_specific 'env_add_path' $manifest $install.architecture)
if($env_set -or $env_add_path) {
if($status.installed) {
Write-Output "Environment:"
} else {
Write-Output "Environment: (simulated)"
}
}
if($env_set) {
if ($env_set) {
$env_vars = @()
$env_set | Get-Member -member noteproperty | ForEach-Object {
$value = env $_.name $global
if(!$value) {
if (!$value) {
$value = format $env_set.$($_.name) @{ "dir" = $dir }
}
Write-Output " $($_.name)=$value"
$env_vars += "$($_.name) = $value"
}
$item.'Environment Variables' = $env_vars -join "`n"
}
if($env_add_path) {
if ($env_add_path) {
$env_path = @()
$env_add_path | Where-Object { $_ } | ForEach-Object {
if($_ -eq '.') {
Write-Output " PATH=%PATH%;$dir"
if ($_ -eq '.') {
$env_path += $dir
} else {
Write-Output " PATH=%PATH%;$dir\$_"
$env_path += "$dir\$_"
}
}
$item.'Path Added' = $env_path -join "`n"
}

if ($manifest.notes) {
# Show notes
$item.Notes = (substitute $manifest.notes @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir}) -join "`n"
}

# Show notes
show_notes $manifest $dir $original_dir $persist_dir
[PSCustomObject]$item

exit 0

0 comments on commit 2651764

Please sign in to comment.