Skip to content

Commit a1e79e0

Browse files
committed
feat(scoop-info): Adopt Resolve-ManifestInformation
- #140 - #2
1 parent b1d5644 commit a1e79e0

File tree

1 file changed

+96
-67
lines changed

1 file changed

+96
-67
lines changed

libexec/scoop-info.ps1

+96-67
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Usage: scoop info [<OPTIONS>] <APP>
22
# Summary: Display information about an application.
3+
# Help: When provided application is installed, all information will be shown based on the locally installed manifest.
34
#
45
# Options:
56
# -h, --help Show help for this command.
@@ -13,14 +14,108 @@ Reset-Alias
1314

1415
$ExitCode = 0
1516
$Options, $Application, $_err = getopt $args 'a:' 'arch='
17+
# TODO: Add some --remote parameter to not use installed manifest
18+
# TODO: Add --global
1619

1720
if ($_err) { Stop-ScoopExecution -Message "scoop info: $_err" -ExitCode 2 }
1821
if (!$Application) { Stop-ScoopExecution -Message 'Parameter <APP> missing' -Usage (my_usage) }
1922

2023
$Application = $Application[0]
2124
$Architecture = Resolve-ArchitectureParameter -Architecture $Options.a, $Options.arch
2225

23-
# TODO: Adopt Resolve-ManifestInformation
26+
$Resolved = $null
27+
try {
28+
$Resolved = Resolve-ManifestInformation -ApplicationQuery $Application
29+
} catch {
30+
Stop-ScoopExecution -Message $_.Exception.Message
31+
}
32+
33+
# TODO: Remove debug
34+
$Resolved | Format-List
35+
36+
# Variables
37+
$Message = @()
38+
$Global = installed $Resolved.ApplicationName $true # TODO: In case both of them are installed only global will be shown
39+
$Status = app_status $Resolved.ApplicationName $global
40+
$Manifest = $Resolved.ManifestObject
41+
# TODO: Switch manifest if it is installed
42+
# TODO: Get install_info
43+
# TODO: Load installed manifest if such specific manifest is installed, $install.bucket -eq $Resolved.Bucket
44+
# or $install.url -eq $Resolved.Url
45+
46+
$dir = (versiondir $Resolved.ApplicationName $Status.version $Global).TrimEnd('\')
47+
$original_dir = (versiondir $Resolved.ApplicationName $Status.version $Global).TrimEnd('\')
48+
$persist_dir = (persistdir $Resolved.ApplicationName $Global).TrimEnd('\')
49+
50+
# TODO: Remove debug
51+
$Status | Format-List
52+
53+
$binaries = @(arch_specific 'bin' $Manifest $Architecture)
54+
if ($binaries) {
55+
$Message += 'Binaries:'
56+
$add = ''
57+
foreach ($b in $binaries) {
58+
$addition = "$b"
59+
if ($b -is [System.Array]) {
60+
$addition = $b[0]
61+
if ($b[1]) {
62+
$addition = "$($b[1]).exe"
63+
}
64+
}
65+
$add = "$add $addition"
66+
}
67+
$Message += $add
68+
}
69+
70+
#region Environment
71+
$env_set = arch_specific 'env_set' $Manifest $Architecture
72+
$env_add_path = @(arch_specific 'env_add_path' $Manifest $Architecture)
73+
74+
if ($env_set -or $env_add_path) {
75+
$m = 'Environment:'
76+
if (!$Status.installed) { $m += ' (simulated)' }
77+
$Message += $m
78+
}
79+
80+
if ($env_set) {
81+
foreach ($es in $env_set | Get-Member -MemberType 'NoteProperty') {
82+
$value = env $es.Name $Global
83+
if (!$value) {
84+
$value = format $env_set.$($es.name) @{ 'dir' = $dir }
85+
}
86+
$Message += " $($es.name)=$value"
87+
}
88+
}
89+
if ($env_add_path) {
90+
# TODO: Should be path rather joined on one line or with multiple PATH=??
91+
# Original:
92+
# PATH=%PATH%;C:\SCOOP\apps\yarn\current\global\node_modules\.bin
93+
# PATH=%PATH%;C:\SCOOP\apps\yarn\current\Yarn\bin
94+
# vs:
95+
# PATH=%PATH%;C:\SCOOP\apps\yarn\current\global\node_modules\.bin;C:\SCOOP\apps\yarn\current\Yarn\bin
96+
foreach ($ea in $env_add_path | Where-Object { $_ }) {
97+
$to = "$dir"
98+
if ($ea -ne '.') {
99+
$to = "$to\$ea"
100+
}
101+
$Message += " PATH=%PATH%;$to"
102+
}
103+
}
104+
#endregion Environment
105+
106+
# Available versions:
107+
$vers = Find-BucketDirectory -Name $resolved.Bucket | Join-Path -ChildPath "old\$Application" | Get-ChildItem -ErrorAction 'SilentlyContinue' -File |
108+
Where-Object -Property 'Name' -Match -Value "\.($ALLOWED_MANIFEST_EXTENSION_REGEX)$"
109+
110+
if ($vers.Count -gt 0) { $message += "Available Versions: $($vers.BaseName -join ', ')" }
111+
112+
Write-UserMessage -Message $message -Output
113+
114+
# Show notes
115+
show_notes $Manifest $dir $original_dir $persist_dir
116+
117+
exit $ExitCode
118+
24119
if ($Application -match '^(ht|f)tps?://|\\\\') {
25120
# check if $Application is a URL or UNC path
26121
$url = $Application
@@ -112,69 +207,3 @@ if ($status.installed) {
112207
} else {
113208
$message += 'Installed: No'
114209
}
115-
116-
$binaries = @(arch_specific 'bin' $manifest $Architecture)
117-
if ($binaries) {
118-
$message += 'Binaries:'
119-
$add = ''
120-
$binaries | ForEach-Object {
121-
$addition = "$_"
122-
if ($_ -is [System.Array]) {
123-
$addition = $_[0]
124-
if ($_[1]) {
125-
$addition = "$($_[1]).exe"
126-
}
127-
}
128-
$add = "$add $addition"
129-
}
130-
$message += $add
131-
}
132-
133-
$env_set = arch_specific 'env_set' $manifest $Architecture
134-
$env_add_path = @(arch_specific 'env_add_path' $manifest $Architecture)
135-
136-
if ($env_set -or $env_add_path) {
137-
$m = 'Environment:'
138-
if (!$status.installed) {
139-
$m += ' (simulated)'
140-
}
141-
$message += $m
142-
}
143-
144-
if ($env_set) {
145-
$env_set | Get-Member -MemberType 'NoteProperty' | ForEach-Object {
146-
$value = env $_.name $global
147-
if (!$value) {
148-
$value = format $env_set.$($_.name) @{ 'dir' = $dir }
149-
}
150-
$message += " $($_.name)=$value"
151-
}
152-
}
153-
if ($env_add_path) {
154-
# TODO: Should be path rather joined on one line or with multiple PATH=??
155-
# Original:
156-
# PATH=%PATH%;C:\SCOOP\apps\yarn\current\global\node_modules\.bin
157-
# PATH=%PATH%;C:\SCOOP\apps\yarn\current\Yarn\bin
158-
# vs:
159-
# PATH=%PATH%;C:\SCOOP\apps\yarn\current\global\node_modules\.bin;C:\SCOOP\apps\yarn\current\Yarn\bin
160-
$env_add_path | Where-Object { $_ } | ForEach-Object {
161-
$to = "$dir"
162-
if ($_ -ne '.') {
163-
$to = "$to\$_"
164-
}
165-
$message += " PATH=%PATH%;$to"
166-
}
167-
}
168-
169-
# Available versions:
170-
$vers = Find-BucketDirectory -Name $bucket | Join-Path -ChildPath "old\$Application" | Get-ChildItem -ErrorAction 'SilentlyContinue' -File |
171-
Where-Object -Property 'Name' -Match -Value "\.($ALLOWED_MANIFEST_EXTENSION_REGEX)$"
172-
173-
if ($vers.Count -gt 0) { $message += "Available Versions: $($vers.BaseName -join ', ')" }
174-
175-
Write-UserMessage -Message $message -Output
176-
177-
# Show notes
178-
show_notes $manifest $dir $original_dir $persist_dir
179-
180-
exit $ExitCode

0 commit comments

Comments
 (0)