Skip to content

Commit

Permalink
feat(scoop-cat): Adopt Resolve-ManifestInformation (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed Jun 19, 2021
1 parent 4145da5 commit 9d0d077
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 41 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

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

- **scoop-cat**: Add `-f`, `--format` options
- Adopt new resolve function for parameter passing
- **scoop-cat**
- **scoop-download**

## [0.6](https://github.com/Ash258/Scoop-Core/milestone/4)

### 0.6-pre4
Expand Down
49 changes: 23 additions & 26 deletions libexec/scoop-cat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,46 @@
# Summary: Show content of specified manifest(s).
#
# Options:
# -h, --help Show help for this command.
# -h, --help Show help for this command.
# -f, --format <json|yaml> Show manifest in specific format. Json will be considered as default when this parameter is not provided.

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

$ExitCode = 0
$Problems = 0
$Options, $Applications, $_err = getopt $args
$Options, $Applications, $_err = getopt $args 'f:' 'format='

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

$Format = $Options.f, $Options.format, 'json' | Where-Object { ! [String]::IsNullOrEmpty($_) } | Select-Object -First 1
if ($Format -notin $ALLOWED_MANIFEST_EXTENSION) { Stop-ScoopExecution -Message "Format '$Format' is not supported" -ExitCode 2 }

foreach ($app in $Applications) {
# Prevent leaking variables from previous iteration
$cleanAppName = $bucket = $version = $appName = $manifest = $foundBucket = $url = $null

# TODO: Adopt Resolve-ManifestInformation
$cleanAppName, $bucket, $version = parse_app $app
$appName, $manifest, $foundBucket, $url = Find-Manifest $cleanAppName $bucket
if ($null -eq $bucket) { $bucket = $foundBucket }

# Handle potential use case, which should not appear, but just in case
# If parsed name/bucket is not same as the provided one
if ((!$url) -and (($cleanAppName -ne $appName) -or ($bucket -ne $foundBucket))) {
debug $bucket
debug $cleanAppName
debug $foundBucket
debug $appName
Write-UserMessage -Message 'Found application name or bucket is not same as requested' -Err
$resolved = $null
try {
$resolved = Resolve-ManifestInformation -ApplicationQuery $app
} catch {
++$Problems

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $appName -Bucket $bucket -Title $title -Body $body }

continue
}

if ($manifest) {
Write-UserMessage -Message "Showing manifest for $app" -Color 'Green'
debug $resolved

# TODO: YAML
$manifest | ConvertToPrettyJson | Write-UserMessage -Output
} else {
Write-UserMessage -Message "Manifest for $app not found" -Err
++$Problems
continue
$output = $resolved.ManifestObject | ConvertTo-Manifest -Extension $Format

if ($output) {
Write-UserMessage -Message "Showing manifest for '$app'" -Success # TODO: Add better text with parsed appname, version, url/bucket
Write-UserMessage -Message $output -Output
}
}

Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-download.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ foreach ($app in $application) {
debug $resolved

# TODO: Remove not neeeded variables. Keep them for now just for less changes
$appName = $resolved.Name
$appName = $resolved.ApplicationName
$manifest = $resolved.ManifestObject
$bucket = $resolved.Bucket
$version = $manifest.version
Expand Down
37 changes: 23 additions & 14 deletions supporting/completion/Scoop-Completion.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $script:SCOOP_SUB_COMMANDS = @{
'utils' = 'auto-pr checkhashes checkurls checkver describe format missing-checkver'
}
$script:SCOOP_SHORT_PARAMETERS = @{
'cat' = 'f'
'cleanup' = 'g k'
'depends' = 'a'
'download' = 's u a b'
Expand All @@ -57,6 +58,7 @@ $script:SCOOP_SHORT_PARAMETERS = @{
'virustotal' = 'a s n'
}
$script:SCOOP_LONG_PARAMETERS = @{
'cat' = 'format'
'cleanup' = 'global cache'
'depends' = 'arch'
'download' = 'skip utility arch all-architectures'
Expand Down Expand Up @@ -87,28 +89,35 @@ foreach ($cmd in $SCOOP_COMMANDS) {
}
}

$script:downloadUtilities = 'native aria2'
$script:supportedArchitectures = '64bit 32bit'
$script:supportedManifestFormats = 'json yaml yml'
$script:SCOOP_PARAMETER_VALUES = @{
'install' = @{
'a' = '32bit 64bit'
'arch' = '32bit 64bit'
'cat' = @{
'f' = $supportedManifestFormats
'format' = $supportedManifestFormats
}
'depends' = @{
'a' = '32bit 64bit'
'arch' = '32bit 64bit'
'a' = $supportedArchitectures
'arch' = $supportedArchitectures
}
'download' = @{
'a' = $supportedArchitectures
'arch' = $supportedArchitectures
'u' = $downloadUtilities
'utility' = $downloadUtilities
}
'info' = @{
'a' = '32bit 64bit'
'arch' = '32bit 64bit'
'a' = $supportedArchitectures
'arch' = $supportedArchitectures
}
'download' = @{
'a' = '32bit 64bit'
'arch' = '32bit 64bit'
'u' = 'native aria2'
'utility' = 'native aria2'
'install' = @{
'a' = $supportedArchitectures
'arch' = $supportedArchitectures
}
'virustotal' = @{
'a' = '32bit 64bit'
'arch' = '32bit 64bit'
'a' = $supportedArchitectures
'arch' = $supportedArchitectures
}
}

Expand Down
2 changes: 2 additions & 0 deletions supporting/completion/scoop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ end
local booleanParser = parser({'true', 'false'})
local architectureParser = parser({'32bit', '64bit'})
local utilityParser = parser({'native', 'aria2'})
local manifestFormatParser = parser({'json', 'yml', 'yaml'})
local configOptions = parser({
'7ZIPEXTRACT_USE_EXTERNAL' .. booleanParser,
'aria2-enabled' .. booleanParser,
Expand Down Expand Up @@ -152,6 +153,7 @@ local scoopParser = parser({
'-h', '--help'
}),
'cat' .. parser({getLocallyAvailableApplicationsByScoop},
'-f' .. manifestFormatParser, '--format' .. manifestFormatParser,
'-h', '--help'
),
'cache' .. parser({'show', 'rm'} .. parser({getScoopCachedFile}),
Expand Down

0 comments on commit 9d0d077

Please sign in to comment.