forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescribe.ps1
63 lines (55 loc) · 1.6 KB
/
describe.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<#
.SYNOPSIS
Search for application description on homepage.
.PARAMETER App
Manifest name to search.
Placeholders are supported.
.PARAMETER Dir
Where to search for manifest(s).
#>
param(
[String] $App = '*',
[Parameter(Mandatory = $true)]
[ValidateScript( {
if (!(Test-Path $_ -Type Container)) {
throw "$_ is not a directory!"
} else {
$true
}
})]
[String] $Dir
)
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"
. "$PSScriptRoot\..\lib\description.ps1"
$Dir = Resolve-Path $Dir
$Queue = @()
Get-ChildItem $Dir "$App.json" | ForEach-Object {
$manifest = parse_json "$Dir\$($_.Name)"
$Queue += , @(($_.Name -replace '\.json$', ''), $manifest)
}
$Queue | ForEach-Object {
$name, $manifest = $_
Write-Host "$name`: " -NoNewline
if (!$manifest.homepage) {
Write-Host "`nNo homepage set." -ForegroundColor Red
return
}
# get description from homepage
try {
$wc = New-Object Net.Webclient
$wc.Headers.Add('User-Agent', (Get-UserAgent))
$home_html = $wc.DownloadString($manifest.homepage)
} catch {
Write-Host "`n$($_.Exception.Message)" -ForegroundColor Red
return
}
$description, $descr_method = find_description $manifest.homepage $home_html
if (!$description) {
Write-Host "`nDescription not found ($($manifest.homepage))" -ForegroundColor Red
return
}
$description = clean_description $description
Write-Host "(found by $descr_method)"
Write-Host " ""$description""" -ForegroundColor Green
}