Skip to content

Commit 7313dc2

Browse files
authored
feat(scoop-info): Adopt Resolve-ManifestInformation (#176)
- Closes #140 - Closes #2
1 parent 6881b84 commit 7313dc2

File tree

5 files changed

+82
-59
lines changed

5 files changed

+82
-59
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

5+
- **scoop-info**: Adopt new resolve function for parameter passing
56
- **Diagnostic**: Ignore completion check when `-noprofile` is used (cmd usage most likely)
67
- **commands**: Short option `-a` will not produce default architecture always
78
- Increase command startup

lib/Applications.ps1

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ function app_status($app, $global) {
178178
$status.hold = ($install_info.hold -eq $true)
179179
$status.bucket = $install_info.bucket
180180
$status.removed = $false
181+
$status.url = $install_info.url
181182

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

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

198+
$status.manifest = $manifest
197199
$status.outdated = $false
198200
if ($status.version -and $status.latest_version) {
199201
$status.outdated = (Compare-Version -ReferenceVersion $status.version -DifferenceVersion $status.latest_version) -ne 0

lib/Versions.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ function Get-InstalledVersion {
6161
$appPath = appdir $AppName $Global
6262
$result = @()
6363

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

lib/manifest.ps1

+4-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ function manifest($app, $bucket, $url) {
567567
return $manifest
568568
}
569569

570-
function installed_manifest($app, $version, $global) {
570+
function installed_manifest($app, $version, $global, [Switch] $PathOnly) {
571571
$d = versiondir $app $version $global
572572

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

594+
if ($PathOnly -and (Test-Path -LiteralPath $manifestPath)) { return $manifestPath }
595+
594596
return ConvertFrom-Manifest -Path $manifestPath
595597
}
596598

597599
# TODO: Deprecate
600+
# Throw, $null return
598601
function install_info($app, $version, $global) {
599602
$d = versiondir $app $version $global
600603
$path = Join-Path $d 'scoop-install.json'

libexec/scoop-info.ps1

+72-55
Original file line numberDiff line numberDiff line change
@@ -10,64 +10,48 @@
1010
}
1111

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

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

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

21-
# TODO: Adopt Resolve-ManifestInformation
22-
if ($Application -match '^(ht|f)tps?://|\\\\') {
23-
# check if $Application is a URL or UNC path
24-
$url = $Application
25-
$Application = appname_from_url $url
26-
$Global = installed $Application $true
27-
$Status = app_status $Application $Global
28-
$Manifest = url_manifest $url
29-
$manifest_file = $url
30-
} else {
31-
# else $Application is a normal app name
32-
$Global = installed $Application $true
33-
$Application, $bucket, $null = parse_app $Application
34-
$Status = app_status $Application $Global
35-
$Manifest, $bucket = find_manifest $Application $bucket
28+
$Resolved = $null
29+
try {
30+
$Resolved = Resolve-ManifestInformation -ApplicationQuery $Application
31+
} catch {
32+
Stop-ScoopExecution -Message $_.Exception.Message
3633
}
3734

38-
if (!$Manifest) { Stop-ScoopExecution -Message "Could not find manifest for '$(show_app $Application $bucket)'" }
39-
40-
$Name = $Application
35+
# Variables
36+
$Name = $Resolved.ApplicationName
37+
$Message = @()
38+
$Global = installed $Name $true
39+
$Status = app_status $Name $Global
40+
$Manifest = $Resolved.ManifestObject
41+
$ManifestPath = @($Resolved.LocalPath)
4142

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

49-
$currentVersion = Select-CurrentVersion -AppName $Name -Global:$Global
50-
$dir = versiondir $Name $currentVersion $Global
51-
$original_dir = versiondir $Name $Manifest.version $Global
52-
$persist_dir = persistdir $Name $Global
53-
54-
if ($Status.installed) {
55-
$manifest_file = manifest_path $Name $install.bucket
56-
if ($install.url) {
57-
$manifest_file = $install.url
58-
}
59-
if ($Status.version -eq $Manifest.version) {
60-
$version_output = $Status.version
61-
} else {
62-
$version_output = "$($Status.version) (Update to $($Manifest.version) available)"
63-
}
64-
$Architecture = $install.architecture
65-
}
46+
$dir = (versiondir $Name $Manifest.version $Global).TrimEnd('\')
47+
$original_dir = (versiondir $Name $Resolved.Version $Global).TrimEnd('\')
48+
$persist_dir = (persistdir $Name $Global).TrimEnd('\')
49+
$up = if ($Status.outdated) { 'Yes' } else { 'No' }
6650

6751
$Message = @("Name: $Name")
68-
$Message += "Version: $version_output"
52+
$Message += "Version: $($Manifest.Version)"
6953
if ($Manifest.description) { $Message += "Description: $($Manifest.description)" }
70-
if ($Manifest.homepage) { $Message += "Website: $($Manifest.homepage)" }
54+
if ($Manifest.homepage) { $Message += "Homepage: $($Manifest.homepage)" }
7155

7256
# Show license
7357
# TODO: Rework
@@ -85,6 +69,7 @@ if ($Manifest.license) {
8569
}
8670
$Message += "License: $license"
8771
}
72+
8873
if ($Manifest.changelog) {
8974
$ch = $Manifest.changelog
9075
if (!$ch.StartsWith('http')) {
@@ -98,25 +83,58 @@ if ($Manifest.changelog) {
9883
}
9984

10085
# Manifest file
101-
$Message += @('Manifest:', " $manifest_file")
86+
$Message += 'Manifest:'
87+
foreach ($m in $ManifestPath) { $Message += " $m" }
88+
89+
# Bucket info
90+
if ($Resolved.Bucket) {
91+
$_m = "Bucket: $($Resolved.Bucket)"
92+
$path = Find-BucketDirectory -Bucket $Resolved.Bucket
93+
94+
if ($path) {
95+
try {
96+
# TODO: Quote
97+
$_u = Invoke-GitCmd -Repository $path -Command 'config' -Argument @('--get', 'remote.origin.url')
98+
if ($LASTEXITCODE -ne 0) { throw 'Ignore' }
99+
if ($_u) { $_m = "$_m ($_u)" }
100+
} catch {
101+
$_u = $null
102+
}
103+
}
104+
105+
$Message += $_m
106+
}
102107

103108
# Show installed versions
104109
if ($Status.installed) {
105-
$Message += 'Installed:'
106-
$versions = Get-InstalledVersion -AppName $Name -Global:$Global
107-
$versions | ForEach-Object {
108-
$dir = versiondir $Name $_ $Global
109-
if ($Global) { $dir += ' *global*' }
110-
$Message += " $dir"
110+
$_m = 'Installed: Yes'
111+
if ($Global) { $_m = "$_m *global*" }
112+
$Message += $_m
113+
114+
$Message += "Installation path: $dir"
115+
116+
$v = Get-InstalledVersion -AppName $Name -Global:$Global
117+
if ($v.Count -gt 0) {
118+
$Message += "Installed versions: $($v -join ', ')"
111119
}
120+
$Message += "Update available: $up"
121+
122+
$InstallInfo = install_info $Name $Manifest.version $Global
123+
$Architecture = $InstallInfo.architecture
112124
} else {
113-
$Message += 'Installed: No'
125+
$inst = 'Installed: No'
126+
# if ($reason) { $inst = "$inst ($reason)" }
127+
$Message += $inst
114128
}
115129

130+
$arm64Support = 'No'
131+
if ($Manifest.architecture.arm64) { $arm64Support = 'Yes' }
132+
$Message += "arm64 Support: $arm64Support"
133+
116134
$binaries = @(arch_specific 'bin' $Manifest $Architecture)
117135
if ($binaries) {
118136
$Message += 'Binaries:'
119-
$add = ''
137+
$add = ' '
120138
foreach ($b in $binaries) {
121139
$addition = "$b"
122140
if ($b -is [System.Array]) {
@@ -167,10 +185,9 @@ if ($env_add_path) {
167185
#endregion Environment
168186

169187
# Available versions:
170-
$vers = Find-BucketDirectory -Name $bucket | Join-Path -ChildPath "old\$Name" | Get-ChildItem -ErrorAction 'SilentlyContinue' -File |
188+
$vers = Find-BucketDirectory -Name $Resolved.Bucket | Join-Path -ChildPath "old\$Name" | Get-ChildItem -ErrorAction 'SilentlyContinue' -File |
171189
Where-Object -Property 'Name' -Match -Value "\.($ALLOWED_MANIFEST_EXTENSION_REGEX)$"
172-
173-
if ($vers.Count -gt 0) { $Message += "Available Versions: $($vers.BaseName -join ', ')" }
190+
if ($vers.Count -gt 0) { $Message += "Available archived versions: $($vers.BaseName -join ', ')" }
174191

175192
Write-UserMessage -Message $Message -Output
176193

0 commit comments

Comments
 (0)