This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
67 lines (58 loc) · 2.13 KB
/
mod.ts
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
import { readline } from "https://deno.land/x/readline/mod.ts";
import { cac } from "https://unpkg.com/cac/mod.ts";
import { Github } from "./src/github.ts";
import { Cli } from "./src/cli.ts";
import { Version } from "./src/github/types.ts";
async function install(question: string = "Which the version do you want?") {
const prefixLine = " ";
const github = new Github();
const versions = (await github.getVersions()).map((version) =>
prefixLine + version + "\n"
).slice(0, 7);
await Cli.write("\n")
.then((_: void) => Cli.write(versions.join(""), Cli.COLOR.FgCyan))
.then((_: void) => Cli.write("\n"))
.then((_: void) => Cli.write(question, Cli.COLOR.Reset))
.then((_: void) => Cli.write("\n> "));
const rl = readline(Deno.stdin);
const input: string = await new TextDecoder().decode((await rl.next()).value);
await Cli.install(input);
await Cli.write("\nYou need to write following the `.bash_profile`\n")
.then((_: void) => Cli.write("export PATH=$HOME/.cret/bin:$PATH"))
}
async function uninstall(inputVersion: string) {
Cli.uninstall(inputVersion)
}
async function lsRemote() {
const versions = (await Cli.lsRemote()).map(v => v + "\n")
await Cli.write(versions.join(""), Cli.COLOR.FgCyan)
}
async function ls() {
const installed = (Cli.ls()).map((version) => version + "\n");
const now = Cli.now();
await Cli.write(`now: ${now}\n`)
.then((_: void) => Cli.write("\n"))
.then((_: void) => Cli.write(installed.join(""), Cli.COLOR.FgGreen))
}
async function use(inputVersion: string) {
Cli.use(inputVersion);
}
const cli = cac("cret");
cli
.command("install", "install new Deno version")
.action((_otherFiles, _options) => install());
cli
.command("uninstall <version>", "Remove your Deno version")
.action((version, _otherFiles, _options) => uninstall(version));
cli
.command("ls-remote", "List up Deno version")
.action((options) => lsRemote());
cli
.command("ls", "list up installed")
.action((_) => ls());
cli
.command("use <version>", "Change your Deno version")
.action((version, _otherFiles, _options) => use(version));
cli.help()
cli.version("1.0.0")
cli.parse();