diff --git a/CHANGELOG.md b/CHANGELOG.md index 401357b371..0e5d8902f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/Applications.ps1 b/lib/Applications.ps1 index 56de8c1a9b..a5be5a9e3d 100644 --- a/lib/Applications.ps1 +++ b/lib/Applications.ps1 @@ -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) { @@ -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 diff --git a/lib/Versions.ps1 b/lib/Versions.ps1 index 350d37d170..e9d87b4681 100644 --- a/lib/Versions.ps1 +++ b/lib/Versions.ps1 @@ -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 } } diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 3bc9e36529..3a310807f1 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -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 @@ -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' diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index 44a0dbc35f..e5859f010b 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -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 missing' -Usage (my_usage) } +if ($Application.Count -gt 1) { Write-UserMessage -Message 'Multiple 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 @@ -85,6 +69,7 @@ if ($Manifest.license) { } $Message += "License: $license" } + if ($Manifest.changelog) { $ch = $Manifest.changelog if (!$ch.StartsWith('http')) { @@ -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]) { @@ -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