-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
74 lines (60 loc) · 2.2 KB
/
main.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
68
69
70
71
72
73
74
import { Command } from "npm:commander";
import add from "./commands/add.ts";
import global from "./commands/global.ts";
import local from "./commands/local.ts";
import newCommand from "./commands/new.ts";
import register from "./commands/register.ts";
import setup from "./commands/setup.ts";
import upgrade from "./commands/upgrade.ts";
import versions from "./commands/versions.ts";
import { version } from "./constants.ts";
export const program = new Command();
const actionRunner = (fn: (...args: any[]) => Promise<any>) => {
return (...args: any[]): any =>
fn(...args)
.then(
(value) =>
(typeof value === "string" ||
typeof value === "number") && console.log(value),
)
.catch(
(error) => console.error(error.message),
);
};
program
.name("drenv")
.description("CLI to manage DragonRuby environments")
.version(version);
program.command("setup")
.description("Setup your shell profile to use drenv")
.action(actionRunner(setup));
program.command("new")
.argument("<name>", "Name of the new project")
.description("Create a new DragonRuby project")
.action(actionRunner(newCommand));
program.command("register")
.argument("<path>", "Path to a fresh DragonRuby directory")
.summary("Register a DragonRuby installation")
.description(
"Register a DragonRuby installation. This moves the installation to the $HOME/.drenv directory.",
)
.action(actionRunner(register));
program.command("add")
.argument("<recipe>", "Name of the recipe to add")
.description("Setup a pre-configured library")
.action(actionRunner(add));
program.command("global")
.argument("[version]", "Version of DragonRuby to use")
.description("Get or set the global version of DragonRuby")
.action(actionRunner(global));
program.command("local")
.argument("[version]", "Version of DragonRuby to use")
.description("Get or set the local version of DragonRuby")
.action(actionRunner(local));
program.command("versions")
.description("List out all locally installed versions of DragonRuby")
.action(actionRunner(versions));
program.command("upgrade")
.description("Upgrade the version of drenv")
.action(actionRunner(upgrade));
program.parse();