Skip to content

Commit

Permalink
feat(scoop-info): Adopt Resolve-ManifestInformation (#176)
Browse files Browse the repository at this point in the history
- Closes #140
- Closes #2
  • Loading branch information
Ash258 committed Feb 12, 2022
1 parent 6881b84 commit 7313dc2
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 59 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5)

- **scoop-info**: Adopt new resolve function for parameter passing
- **Diagnostic**: Ignore completion check when `-noprofile` is used (cmd usage most likely)
- **commands**: Short option `-a` will not produce default architecture always
- Increase command startup
Expand Down
2 changes: 2 additions & 0 deletions lib/Applications.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function app_status($app, $global) {
$status.hold = ($install_info.hold -eq $true)
$status.bucket = $install_info.bucket
$status.removed = $false
$status.url = $install_info.url

$todo = $app
if ($install_info.bucket) {
Expand All @@ -194,6 +195,7 @@ function app_status($app, $global) {

if ($manifest.version) { $status.latest_version = $manifest.version }

$status.manifest = $manifest
$status.outdated = $false
if ($status.version -and $status.latest_version) {
$status.outdated = (Compare-Version -ReferenceVersion $status.version -DifferenceVersion $status.latest_version) -ne 0
Expand Down
6 changes: 3 additions & 3 deletions lib/Versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ function Get-InstalledVersion {
$appPath = appdir $AppName $Global
$result = @()

if (Test-Path $appPath -PathType 'Container') {
if (Test-Path -LiteralPath $appPath -PathType 'Container') {
# TODO: Keep only scoop-install.json
$arr = @((Get-ChildItem "$appPath\*\install.json"), (Get-ChildItem "$appPath\*\scoop-install.json"))
$versions = @(($arr | Sort-Object -Property LastWriteTimeUtc).Directory.Name) | Where-Object { $_ -ne 'current' }
$arr = @(Get-ChildItem -Path "$appPath\*\install.json", "$appPath\*\scoop-install.json")
$versions = @(($arr | Sort-Object -Property 'LastWriteTimeUtc').Directory.Name) | Where-Object { $_ -ne 'current' }
if ($versions.Count -gt 0) { $result = $versions }
}

Expand Down
5 changes: 4 additions & 1 deletion lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ function manifest($app, $bucket, $url) {
return $manifest
}

function installed_manifest($app, $version, $global) {
function installed_manifest($app, $version, $global, [Switch] $PathOnly) {
$d = versiondir $app $version $global

#region Migration from non-generic file name
Expand All @@ -591,10 +591,13 @@ function installed_manifest($app, $version, $global) {
}
}

if ($PathOnly -and (Test-Path -LiteralPath $manifestPath)) { return $manifestPath }

return ConvertFrom-Manifest -Path $manifestPath
}

# TODO: Deprecate
# Throw, $null return
function install_info($app, $version, $global) {
$d = versiondir $app $version $global
$path = Join-Path $d 'scoop-install.json'
Expand Down
127 changes: 72 additions & 55 deletions libexec/scoop-info.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,48 @@
}

$ExitCode = 0
# TODO: Add some --remote parameter to not use installed manifest
# -g, --global Gather information from globally installed application if application is installed both locally and globally.
# Useful for pre-check of installed specific application in automatic deployments.
# -r, --remote > Remote manifest will be used to get all required information. Ignoring locally installed manifest (scoop-manifest.json).
# $Options, $Application, $_err = Resolve-GetOpt $args 'a:g' 'arch=', 'global'
$Options, $Application, $_err = Resolve-GetOpt $args 'a:' 'arch='

if ($_err) { Stop-ScoopExecution -Message "scoop info: $_err" -ExitCode 2 }
if (!$Application) { Stop-ScoopExecution -Message 'Parameter <APP> missing' -Usage (my_usage) }
if ($Application.Count -gt 1) { Write-UserMessage -Message 'Multiple <APP> parameters is not allowed. Ignoring all except the first.' -Warning }

$Application = $Application[0]
$Architecture = Resolve-ArchitectureParameter -Architecture $Options.a, $Options.arch
# $Global = $Options.'g' -or $Options.'global'

# TODO: Adopt Resolve-ManifestInformation
if ($Application -match '^(ht|f)tps?://|\\\\') {
# check if $Application is a URL or UNC path
$url = $Application
$Application = appname_from_url $url
$Global = installed $Application $true
$Status = app_status $Application $Global
$Manifest = url_manifest $url
$manifest_file = $url
} else {
# else $Application is a normal app name
$Global = installed $Application $true
$Application, $bucket, $null = parse_app $Application
$Status = app_status $Application $Global
$Manifest, $bucket = find_manifest $Application $bucket
$Resolved = $null
try {
$Resolved = Resolve-ManifestInformation -ApplicationQuery $Application
} catch {
Stop-ScoopExecution -Message $_.Exception.Message
}

if (!$Manifest) { Stop-ScoopExecution -Message "Could not find manifest for '$(show_app $Application $bucket)'" }

$Name = $Application
# Variables
$Name = $Resolved.ApplicationName
$Message = @()
$Global = installed $Name $true
$Status = app_status $Name $Global
$Manifest = $Resolved.ManifestObject
$ManifestPath = @($Resolved.LocalPath)

$install = install_info $Name $Status.version $Global
$Status.installed = $install.bucket -eq $bucket
$version_output = $Manifest.version
if (!$manifest_file) {
$manifest_file = manifest_path $Name $bucket
}
$ManifestPath = $ManifestPath, $Resolved.Url, (installed_manifest $Name $Manifest.version $Global -PathOnly), $Resolved.LocalPath |
Where-Object { ![String]::IsNullOrEmpty($_) } | Select-Object -Unique

$currentVersion = Select-CurrentVersion -AppName $Name -Global:$Global
$dir = versiondir $Name $currentVersion $Global
$original_dir = versiondir $Name $Manifest.version $Global
$persist_dir = persistdir $Name $Global

if ($Status.installed) {
$manifest_file = manifest_path $Name $install.bucket
if ($install.url) {
$manifest_file = $install.url
}
if ($Status.version -eq $Manifest.version) {
$version_output = $Status.version
} else {
$version_output = "$($Status.version) (Update to $($Manifest.version) available)"
}
$Architecture = $install.architecture
}
$dir = (versiondir $Name $Manifest.version $Global).TrimEnd('\')
$original_dir = (versiondir $Name $Resolved.Version $Global).TrimEnd('\')
$persist_dir = (persistdir $Name $Global).TrimEnd('\')
$up = if ($Status.outdated) { 'Yes' } else { 'No' }

$Message = @("Name: $Name")
$Message += "Version: $version_output"
$Message += "Version: $($Manifest.Version)"
if ($Manifest.description) { $Message += "Description: $($Manifest.description)" }
if ($Manifest.homepage) { $Message += "Website: $($Manifest.homepage)" }
if ($Manifest.homepage) { $Message += "Homepage: $($Manifest.homepage)" }

# Show license
# TODO: Rework
Expand All @@ -85,6 +69,7 @@ if ($Manifest.license) {
}
$Message += "License: $license"
}

if ($Manifest.changelog) {
$ch = $Manifest.changelog
if (!$ch.StartsWith('http')) {
Expand All @@ -98,25 +83,58 @@ if ($Manifest.changelog) {
}

# Manifest file
$Message += @('Manifest:', " $manifest_file")
$Message += 'Manifest:'
foreach ($m in $ManifestPath) { $Message += " $m" }

# Bucket info
if ($Resolved.Bucket) {
$_m = "Bucket: $($Resolved.Bucket)"
$path = Find-BucketDirectory -Bucket $Resolved.Bucket

if ($path) {
try {
# TODO: Quote
$_u = Invoke-GitCmd -Repository $path -Command 'config' -Argument @('--get', 'remote.origin.url')
if ($LASTEXITCODE -ne 0) { throw 'Ignore' }
if ($_u) { $_m = "$_m ($_u)" }
} catch {
$_u = $null
}
}

$Message += $_m
}

# Show installed versions
if ($Status.installed) {
$Message += 'Installed:'
$versions = Get-InstalledVersion -AppName $Name -Global:$Global
$versions | ForEach-Object {
$dir = versiondir $Name $_ $Global
if ($Global) { $dir += ' *global*' }
$Message += " $dir"
$_m = 'Installed: Yes'
if ($Global) { $_m = "$_m *global*" }
$Message += $_m

$Message += "Installation path: $dir"

$v = Get-InstalledVersion -AppName $Name -Global:$Global
if ($v.Count -gt 0) {
$Message += "Installed versions: $($v -join ', ')"
}
$Message += "Update available: $up"

$InstallInfo = install_info $Name $Manifest.version $Global
$Architecture = $InstallInfo.architecture
} else {
$Message += 'Installed: No'
$inst = 'Installed: No'
# if ($reason) { $inst = "$inst ($reason)" }
$Message += $inst
}

$arm64Support = 'No'
if ($Manifest.architecture.arm64) { $arm64Support = 'Yes' }
$Message += "arm64 Support: $arm64Support"

$binaries = @(arch_specific 'bin' $Manifest $Architecture)
if ($binaries) {
$Message += 'Binaries:'
$add = ''
$add = ' '
foreach ($b in $binaries) {
$addition = "$b"
if ($b -is [System.Array]) {
Expand Down Expand Up @@ -167,10 +185,9 @@ if ($env_add_path) {
#endregion Environment

# Available versions:
$vers = Find-BucketDirectory -Name $bucket | Join-Path -ChildPath "old\$Name" | Get-ChildItem -ErrorAction 'SilentlyContinue' -File |
$vers = Find-BucketDirectory -Name $Resolved.Bucket | Join-Path -ChildPath "old\$Name" | Get-ChildItem -ErrorAction 'SilentlyContinue' -File |
Where-Object -Property 'Name' -Match -Value "\.($ALLOWED_MANIFEST_EXTENSION_REGEX)$"

if ($vers.Count -gt 0) { $Message += "Available Versions: $($vers.BaseName -join ', ')" }
if ($vers.Count -gt 0) { $Message += "Available archived versions: $($vers.BaseName -join ', ')" }

Write-UserMessage -Message $Message -Output

Expand Down

0 comments on commit 7313dc2

Please sign in to comment.