Skip to content

Commit af3ab2f

Browse files
committed
feat(scoop-cat): Adopt Resolve-ManifestInformation
- #140
1 parent aa017b0 commit af3ab2f

File tree

4 files changed

+55
-40
lines changed

4 files changed

+55
-40
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5)
4+
5+
- **scoop-cat**: Add `-f`, `--format` options
6+
- Adopt new resolve function for parameter passing
7+
- **scoop-cat**
8+
- **scoop-download**
9+
310
## [0.6](https://github.com/Ash258/Scoop-Core/milestone/4)
411

512
### 0.6-pre4

libexec/scoop-cat.ps1

+23-26
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,46 @@
22
# Summary: Show content of specified manifest(s).
33
#
44
# Options:
5-
# -h, --help Show help for this command.
5+
# -h, --help Show help for this command.
6+
# -f, --format <json|yaml> Show manifest in specific format. Json will be considered as default when this parameter is not provided.
67

78
'core', 'getopt', 'help', 'Helpers', 'install', 'manifest' | ForEach-Object {
89
. (Join-Path $PSScriptRoot "..\lib\$_.ps1")
910
}
1011

1112
$ExitCode = 0
1213
$Problems = 0
13-
$Options, $Applications, $_err = getopt $args
14+
$Options, $Applications, $_err = getopt $args 'f:' 'format='
1415

1516
if ($_err) { Stop-ScoopExecution -Message "scoop cat: $_err" -ExitCode 2 }
1617
if (!$Applications) { Stop-ScoopExecution -Message 'Parameter <APP> missing' -Usage (my_usage) }
1718

19+
$Format = $Options.f, $Options.format, 'json' | Where-Object { ! [String]::IsNullOrEmpty($_) } | Select-Object -First 1
20+
if ($Format -notin $ALLOWED_MANIFEST_EXTENSION) { Stop-ScoopExecution -Message "Format '$Format' is not supported" -ExitCode 2 }
21+
1822
foreach ($app in $Applications) {
19-
# Prevent leaking variables from previous iteration
20-
$cleanAppName = $bucket = $version = $appName = $manifest = $foundBucket = $url = $null
21-
22-
# TODO: Adopt Resolve-ManifestInformation
23-
$cleanAppName, $bucket, $version = parse_app $app
24-
$appName, $manifest, $foundBucket, $url = Find-Manifest $cleanAppName $bucket
25-
if ($null -eq $bucket) { $bucket = $foundBucket }
26-
27-
# Handle potential use case, which should not appear, but just in case
28-
# If parsed name/bucket is not same as the provided one
29-
if ((!$url) -and (($cleanAppName -ne $appName) -or ($bucket -ne $foundBucket))) {
30-
debug $bucket
31-
debug $cleanAppName
32-
debug $foundBucket
33-
debug $appName
34-
Write-UserMessage -Message 'Found application name or bucket is not same as requested' -Err
23+
$resolved = $null
24+
try {
25+
$resolved = Resolve-ManifestInformation -ApplicationQuery $app
26+
} catch {
3527
++$Problems
28+
29+
$title, $body = $_.Exception.Message -split '\|-'
30+
if (!$body) { $body = $title }
31+
Write-UserMessage -Message $body -Err
32+
debug $_.InvocationInfo
33+
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $appName -Bucket $bucket -Title $title -Body $body }
34+
3635
continue
3736
}
3837

39-
if ($manifest) {
40-
Write-UserMessage -Message "Showing manifest for $app" -Color 'Green'
38+
debug $resolved
4139

42-
# TODO: YAML
43-
$manifest | ConvertToPrettyJson | Write-UserMessage -Output
44-
} else {
45-
Write-UserMessage -Message "Manifest for $app not found" -Err
46-
++$Problems
47-
continue
40+
$output = $resolved.ManifestObject | ConvertTo-Manifest -Extension $Format
41+
42+
if ($output) {
43+
Write-UserMessage -Message "Showing manifest for '$app'" -Success # TODO: Add better text with parsed appname, version, url/bucket
44+
Write-UserMessage -Message $output -Output
4845
}
4946
}
5047

supporting/completion/Scoop-Completion.psm1

+23-14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ $script:SCOOP_SUB_COMMANDS = @{
4242
'utils' = 'auto-pr checkhashes checkurls checkver describe format missing-checkver'
4343
}
4444
$script:SCOOP_SHORT_PARAMETERS = @{
45+
'cat' = 'f'
4546
'cleanup' = 'g k'
4647
'depends' = 'a'
4748
'download' = 's u a b'
@@ -57,6 +58,7 @@ $script:SCOOP_SHORT_PARAMETERS = @{
5758
'virustotal' = 'a s n'
5859
}
5960
$script:SCOOP_LONG_PARAMETERS = @{
61+
'cat' = 'format'
6062
'cleanup' = 'global cache'
6163
'depends' = 'arch'
6264
'download' = 'skip utility arch all-architectures'
@@ -87,28 +89,35 @@ foreach ($cmd in $SCOOP_COMMANDS) {
8789
}
8890
}
8991

92+
$script:downloadUtilities = 'native aria2'
93+
$script:supportedArchitectures = '64bit 32bit'
94+
$script:supportedManifestFormats = 'json yaml yml'
9095
$script:SCOOP_PARAMETER_VALUES = @{
91-
'install' = @{
92-
'a' = '32bit 64bit'
93-
'arch' = '32bit 64bit'
96+
'cat' = @{
97+
'f' = $supportedManifestFormats
98+
'format' = $supportedManifestFormats
9499
}
95100
'depends' = @{
96-
'a' = '32bit 64bit'
97-
'arch' = '32bit 64bit'
101+
'a' = $supportedArchitectures
102+
'arch' = $supportedArchitectures
103+
}
104+
'download' = @{
105+
'a' = $supportedArchitectures
106+
'arch' = $supportedArchitectures
107+
'u' = $downloadUtilities
108+
'utility' = $downloadUtilities
98109
}
99110
'info' = @{
100-
'a' = '32bit 64bit'
101-
'arch' = '32bit 64bit'
111+
'a' = $supportedArchitectures
112+
'arch' = $supportedArchitectures
102113
}
103-
'download' = @{
104-
'a' = '32bit 64bit'
105-
'arch' = '32bit 64bit'
106-
'u' = 'native aria2'
107-
'utility' = 'native aria2'
114+
'install' = @{
115+
'a' = $supportedArchitectures
116+
'arch' = $supportedArchitectures
108117
}
109118
'virustotal' = @{
110-
'a' = '32bit 64bit'
111-
'arch' = '32bit 64bit'
119+
'a' = $supportedArchitectures
120+
'arch' = $supportedArchitectures
112121
}
113122
}
114123

supporting/completion/scoop.lua

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ end
1414
local booleanParser = parser({'true', 'false'})
1515
local architectureParser = parser({'32bit', '64bit'})
1616
local utilityParser = parser({'native', 'aria2'})
17+
local manifestFormatParser = parser({'json', 'yml', 'yaml'})
1718
local configOptions = parser({
1819
'7ZIPEXTRACT_USE_EXTERNAL' .. booleanParser,
1920
'aria2-enabled' .. booleanParser,
@@ -152,6 +153,7 @@ local scoopParser = parser({
152153
'-h', '--help'
153154
}),
154155
'cat' .. parser({getLocallyAvailableApplicationsByScoop},
156+
'-f' .. manifestFormatParser, '--format' .. manifestFormatParser,
155157
'-h', '--help'
156158
),
157159
'cache' .. parser({'show', 'rm'} .. parser({getScoopCachedFile}),

0 commit comments

Comments
 (0)