Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scoop-info): Adopt Resolve-ManifestInformation #176

Merged
merged 40 commits into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a1e79e0
feat(scoop-info): Adopt Resolve-ManifestInformation
Ash258 Jul 5, 2021
f9bd22f
wip
Ash258 Jul 5, 2021
412322e
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featInfoResolve
Ash258 Jul 12, 2021
1889b31
wip
Ash258 Jul 12, 2021
e7140e1
remove debug
Ash258 Jul 12, 2021
4d8ae1d
not needed condiition
Ash258 Jul 12, 2021
22a115c
init
Ash258 Jul 12, 2021
39e29a7
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featInfoResolve
Ash258 Aug 8, 2021
d352d81
ch
Ash258 Aug 8, 2021
31a0ea7
arm64 support indication
Ash258 Aug 11, 2021
21a60fc
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featInfoResolve
Ash258 Aug 15, 2021
df03585
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featInfoResolve
Ash258 Sep 13, 2021
bdf7d2d
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featInfoResolve
Ash258 Sep 18, 2021
c2d4a52
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featInfoResolve
Ash258 Oct 16, 2021
e1dddfe
Merge branch 'NEW' into featInfoResolve
Ash258 Oct 31, 2021
3f12194
Merge branch 'NEW' into featInfoResolve
Ash258 Nov 22, 2021
e576128
--global, small progress
Ash258 Nov 22, 2021
ee01b78
Merge branch 'NEW' into featInfoResolve
Ash258 Nov 24, 2021
90a53c8
Merge branch 'NEW' into featInfoResolve
Ash258 Dec 4, 2021
b001f9c
Update CHANGELOG.md
Ash258 Dec 4, 2021
1c090da
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featInfoResolve
Ash258 Dec 8, 2021
3401b05
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featInfoResolve
Ash258 Dec 15, 2021
c6ba93e
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featInfoResolve
Ash258 Dec 18, 2021
a772e89
Merge branch 'NEW' into featInfoResolve
Ash258 Dec 29, 2021
86ca177
fallback with simple
Ash258 Dec 29, 2021
c288dda
join, unique
Ash258 Dec 29, 2021
41f5e81
bucket info
Ash258 Dec 29, 2021
a2d61b5
Merge branch 'NEW' into featInfoResolve
Ash258 Jan 21, 2022
bf6ae5b
Merge branch 'NEW' into featInfoResolve
Ash258 Jan 28, 2022
bb1efb3
Merge branch 'NEW' into featInfoResolve
Ash258 Jan 29, 2022
c702c0a
ch
Ash258 Jan 30, 2022
66d85a6
[ci skip]
Ash258 Jan 30, 2022
4e3f22f
wording
Ash258 Feb 1, 2022
1bfda0b
There is no local preference without the reason not installed
Ash258 Feb 1, 2022
a0f2c21
play it safe; Rather simple adoption then rework
Ash258 Feb 1, 2022
3b7021e
fix
Ash258 Feb 1, 2022
c7e163b
todo: load local manifest if no $Manifest and app installed
Ash258 Feb 1, 2022
7ab63bd
Merge branch 'NEW' into featInfoResolve
Ash258 Feb 9, 2022
e114472
cleanup
Ash258 Feb 12, 2022
6d7952a
better wording; organization; global indication
Ash258 Feb 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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