Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scoop-status): Properly support YML typed manifests #248

Merged
merged 16 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
try with this approach. TODO: Add test, run verification
  • Loading branch information
Ash258 committed Dec 25, 2021
commit 1be08c457e3a4fc81a70f75316e137f7322b53ac
12 changes: 8 additions & 4 deletions lib/Applications.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,15 @@ function app_status($app, $global) {
}

$status.missing_deps = @()
# TODO: Should be handled specific version dependency?
# TODO: Adopt Resolve-ManifestInformation not needed to be fully compatible, consider some simple parsing
# TODO: Better handle different dependencies version
$deps = @(Resolve-DependsProperty -Manifest $manifest) | Where-Object {
$app, $bucket, $null = parse_app $_
return !(installed $app)
try {
$app = Resolve-ManifestInformation -ApplicationQuery $_ -Simple
debug $app
return !(installed $app.ApplicationName)
} catch {
return $true
}
}

if ($deps) { $status.missing_deps += , $deps }
Expand Down
81 changes: 58 additions & 23 deletions lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,23 @@ function Get-LocalManifest {
Get "metadata" about local manifest with support for archived manifests.
.PARAMETER Query
Specifies the file path where manifest is stored.
.PARAMETER Simple
Specifies to return limited information about the resolved manifest.
#>
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param([Parameter(Mandatory, ValueFromPipeline)] [String] $Query)
param([Parameter(Mandatory, ValueFromPipeline)] [String] $Query, [Boolean] $Simple)

process {
$localPath = $manifest = $reqVersion = $null

try {
$manifest = ConvertFrom-Manifest -LiteralPath $Query
$localPath = Get-Item -LiteralPath $Query
} catch {
throw [ScoopException] "File is not a valid manifest ($($_.Exception.Message))" # TerminatingError thrown
throw [ScoopException] "File with manifest does not exist '$Query'"
}

$localPath = Get-Item -LiteralPath $Query
$applicationName = $localPath.BaseName
$reqVersion = $null

# Check if archived version was provided
if ($localPath.FullName -match $_archivedManifestRegex) {
Expand All @@ -204,6 +206,14 @@ function Get-LocalManifest {
$applicationName = $Matches['app']
}

if (!$Simple) {
try {
$manifest = ConvertFrom-Manifest -LiteralPath $Query
} catch {
throw [ScoopException] "File is not a valid manifest ($($_.Exception.Message))" # TerminatingError thrown
}
}

return @{
'Name' = $applicationName
'RequestedVersion' = $reqVersion
Expand All @@ -220,15 +230,35 @@ function Get-RemoteManifest {
Download manifest from provided URL.
.PARAMETER URL
Specifies the URL pointing to manifest.
.PARAMETER Simple
Specifies to return limited information about the resolved manifest.
#>
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param([Parameter(Mandatory, ValueFromPipeline)] [String] $URL)
param([Parameter(Mandatory, ValueFromPipeline)] [String] $URL, [Boolean] $Simple)

process {
# Parse name and extension from URL
$name = Split-Path $URL -Leaf
$extension = ($name -split '\.')[-1]
$name = $name -replace "\.($ALLOWED_MANIFEST_EXTENSION_REGEX)$"

if ($URL -match $_archivedManifestRegex) {
$name = $Matches['manifestName']
$extension = $Matches['manifestExtension']
}

if ($Simple) {
return @{
'Name' = $name
'Manifest' = $null
'Path' = $null
'Print' = $URL
}
}

$str = $null
try {
# TODO: Implement proxy
$wc = New-Object System.Net.Webclient
$wc.Headers.Add('User-Agent', $SHOVEL_USERAGENT)
$str = $wc.DownloadString($URL)
Expand All @@ -244,16 +274,6 @@ function Get-RemoteManifest {

Confirm-DirectoryExistence -Directory $SHOVEL_GENERAL_MANIFESTS_DIRECTORY | Out-Null

# Parse name and extension from URL
$name = Split-Path $URL -Leaf
$extension = ($name -split '\.')[-1]
$name = $name -replace "\.($ALLOWED_MANIFEST_EXTENSION_REGEX)$"

if ($URL -match $_archivedManifestRegex) {
$name = $Matches['manifestName']
$extension = $Matches['manifestExtension']
}

$rand = "$_localAdditionalSeed$(Get-Random)-$(Get-Random)"
$outName = "$name-$rand.$extension"
$manifestFile = Join-Path $SHOVEL_GENERAL_MANIFESTS_DIRECTORY $outName
Expand Down Expand Up @@ -285,10 +305,12 @@ function Get-ManifestFromLookup {
Lookup for manifest in all local buckets and return required information.
.PARAMETER Query
Specifies the lookup query.
.PARAMETER Simple
Specifies to return limited information about the resolved manifest.
#>
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param([Parameter(Mandatory, ValueFromPipeline)] [String] $Query)
param([Parameter(Mandatory, ValueFromPipeline)] [String] $Query, [Boolean] $Simple)

process {
# Get all requested information
Expand All @@ -299,6 +321,17 @@ function Get-ManifestFromLookup {
}
$requestedName, $requestedVersion = $requestedName -split '@'

if ($Simple) {
return @{
'Name' = $name
'Bucket' = $manifestBucket
'RequestedVersion' = $requestedVersion
'Print' = "$manifestBucket/$name$printableRepresentation"
'Manifest' = $null
'Path' = $null
}
}

# Local manifest with specific name in all buckets
$found = @()
$buckets = Get-LocalBucket
Expand Down Expand Up @@ -378,6 +411,8 @@ function Resolve-ManifestInformation {
Find and parse manifest file according to search query. Return universal object with all relevant information about manifest.
.PARAMETER ApplicationQuery
Specifies the string used for looking for manifest.
.PARAMETER Simple
Specifies to return limited information about the resolved manifest.
.EXAMPLE
Resolve-ManifestInformation -ApplicationQuery 'pwsh'
Resolve-ManifestInformation -ApplicationQuery 'pwsh@7.2.0'
Expand All @@ -393,29 +428,29 @@ function Resolve-ManifestInformation {
#>
[CmdletBinding()]
[OutputType([PSCustomObject])]
param([Parameter(Mandatory, ValueFromPipeline)] [String] $ApplicationQuery)
param([Parameter(Mandatory, ValueFromPipeline)] [String] $ApplicationQuery, [Boolean] $Simple)

process {
$manifest = $applicationName = $applicationVersion = $requestedVersion = $bucket = $localPath = $url = $print = $calcBucket = $calcURL = $null

if (Test-Path -LiteralPath $ApplicationQuery) {
$res = Get-LocalManifest -Query $ApplicationQuery
$res = Get-LocalManifest -Query $ApplicationQuery -Simple:$Simple
$applicationName = $res.Name
$applicationVersion = $res.Manifest.version
$requestedVersion = $res.RequestedVersion
$manifest = $res.Manifest
$localPath = $res.Path
$print = $res.Print
} elseif ($ApplicationQuery -match '^https?://') {
$res = Get-RemoteManifest -URL $ApplicationQuery
$res = Get-RemoteManifest -URL $ApplicationQuery -Simple:$Simple
$applicationName = $res.Name
$applicationVersion = $res.Manifest.version
$manifest = $res.Manifest
$localPath = $res.Path
$url = $ApplicationQuery
$print = $res.Print
} elseif ($ApplicationQuery -match $_lookupRegex) {
$res = Get-ManifestFromLookup -Query $ApplicationQuery
$res = Get-ManifestFromLookup -Query $ApplicationQuery -Simple:$Simple
$applicationName = $res.Name
$requestedVersion = $res.RequestedVersion
$applicationVersion = $res.Manifest.version
Expand All @@ -430,7 +465,7 @@ function Resolve-ManifestInformation {
debug $res

# TODO: Validate manifest object
if ($null -eq $manifest.version) {
if (!$Simple -and ($null -eq $manifest.version)) {
debug $manifest
throw [ScoopException] 'Not a valid manifest' # TerminatingError thrown
}
Expand Down