|
2 | 2 | # Summary: Show content of specified manifest(s).
|
3 | 3 | #
|
4 | 4 | # 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. |
6 | 7 |
|
7 | 8 | 'core', 'getopt', 'help', 'Helpers', 'install', 'manifest' | ForEach-Object {
|
8 | 9 | . (Join-Path $PSScriptRoot "..\lib\$_.ps1")
|
9 | 10 | }
|
10 | 11 |
|
11 | 12 | $ExitCode = 0
|
12 | 13 | $Problems = 0
|
13 |
| -$Options, $Applications, $_err = getopt $args |
| 14 | +$Options, $Applications, $_err = getopt $args 'f:' 'format=' |
14 | 15 |
|
15 | 16 | if ($_err) { Stop-ScoopExecution -Message "scoop cat: $_err" -ExitCode 2 }
|
16 | 17 | if (!$Applications) { Stop-ScoopExecution -Message 'Parameter <APP> missing' -Usage (my_usage) }
|
17 | 18 |
|
| 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 | + |
18 | 22 | 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 { |
35 | 27 | ++$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 | + |
36 | 35 | continue
|
37 | 36 | }
|
38 | 37 |
|
39 |
| - if ($manifest) { |
40 |
| - Write-UserMessage -Message "Showing manifest for $app" -Color 'Green' |
| 38 | + debug $resolved |
41 | 39 |
|
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 |
48 | 45 | }
|
49 | 46 | }
|
50 | 47 |
|
|
0 commit comments