forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoop-create.ps1
69 lines (55 loc) · 1.44 KB
/
scoop-create.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
64
65
66
67
68
69
# Usage: scoop create <url>
# Summary: Create a custom app manifest
# Help: Create your own custom app manifest
param($url)
function create_manifest($url) {
$manifest = new_manifest
$manifest.url = $url
$url_parts = $null
try {
$url_parts = parse_url $url
}
catch {
abort "Error: $url is not a valid URL"
}
$name = choose_item $url_parts "App name"
$name = if ($name.Length -gt 0) {
$name
}
else {
file_name ($url_parts | select-object -last 1)
}
$manifest.version = choose_item $url_parts "Version"
$manifest | convertto-json | out-file -filepath "$name.json" -encoding utf8
$manifest_path = join-path $pwd "$name.json"
write-host "Created '$manifest_path'."
}
function new_manifest() {
@{ "homepage" = ""; "license" = ""; "version" = ""; "url" = "";
"hash" = ""; "extract_dir" = ""; "bin" = ""; "depends" = "" }
}
function file_name($segment) {
$segment.substring(0, $segment.lastindexof('.'))
}
function parse_url($url) {
$uri = new-object Uri $url
$uri.pathandquery.substring(1).split("/")
}
function choose_item($list, $query) {
for ($i = 0; $i -lt $list.count; $i++) {
$item = $list[$i]
write-host "$($i + 1)) $item"
}
$sel = read-host $query
if ($sel.trim() -match '^[0-9+]$') {
return $list[$sel-1]
}
$sel
}
if (!$url) {
scoop help create
}
else {
create_manifest $url
}
exit 0