Skip to content

Commit ad90c74

Browse files
committed
deps.ts: Factor out version prompt into a separate promptVersion() helper function
1 parent 130ace4 commit ad90c74

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

deps.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,7 @@ Deno.remove(dropExtension(rclone), {recursive: true});
3535
console.log("All dependencies fetched!");
3636

3737
async function releaseUrl(org: string, repo: string, suffix?: string): Promise<string> {
38-
let info = await releaseInfo(org, repo);
39-
const tag = info.tag_name.match(/([^0-9]+)(.+)/);
40-
if(!tag) {
41-
console.error("Unexpected error parsing latest " + repo + " tag name!");
42-
Deno.exit(2);
43-
}
44-
45-
const version = prompt(repo + " version to download?", tag[2]);
46-
if(version != tag[2])
47-
info = await releaseInfo(org, repo, tag[1] + version);
48-
38+
const info = await promptVersion(org, repo);
4939
if(suffix) {
5040
// Download binary release.
5141
const file = info.assets.find(function(each) {
@@ -58,7 +48,22 @@ async function releaseUrl(org: string, repo: string, suffix?: string): Promise<s
5848
return file.browser_download_url;
5949
} else
6050
// Download source release.
61-
return "https://github.com/" + org + "/" + repo + "/archive/refs/tags/v" + version + ".tar.gz";
51+
return "https://github.com/" + org + "/" + repo + "/archive/refs/tags/" + info.tag_name + ".tar.gz";
52+
}
53+
54+
async function promptVersion(org: string, repo: string): Promise<ReleaseInfo> {
55+
let info = await releaseInfo(org, repo);
56+
const tag = info.tag_name.match(/([^0-9]+)(.+)/);
57+
if(!tag) {
58+
console.error("Unexpected error parsing latest " + repo + " tag name!");
59+
Deno.exit(2);
60+
}
61+
62+
const version = prompt(repo + " version to download?", tag[2]);
63+
if(version != tag[2])
64+
info = await releaseInfo(org, repo, tag[1] + version);
65+
66+
return info;
6267
}
6368

6469
async function releaseInfo(org: string, repo: string, tag = ""): Promise<ReleaseInfo> {

0 commit comments

Comments
 (0)