-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·69 lines (61 loc) · 2.03 KB
/
index.js
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
#!/usr/bin/env node
const commands = require("./src/commands");
const { Command } = require("commander");
const program = new Command();
program.version("0.0.1");
function onSuccess(data = "") {
console.log("Command completed with success");
console.log(data);
process.exit(0);
}
function onFail(error) {
console.log("Command completed with failure");
console.error(error);
process.exit(1);
}
program
.command("create <server_config>")
.description("create an instance for the given config")
.action((serverConfig) => {
console.log("create command called");
const config = require(`./servers/${serverConfig}.json`);
console.table(config);
commands
.createInstance({
osId: config.osId,
plan: config.plan,
region: config.region,
sshKeyId: process.env.VULTR_SSH_KEY_ID,
})
.then(onSuccess)
.catch(onFail);
});
program
.command("delete <instance_id>")
.description("delete instance for given id")
.action((instanceId) => {
console.log("delete command called");
commands.deleteInstance(instanceId).then(onSuccess).catch(onFail);
});
program
.command("list")
.description("list instances")
.action(() => {
console.log("list command called");
commands.listInstances().then(onSuccess).catch(onFail);
});
program
.command("provision")
.description("provision instance as TO4 server for given ip")
.requiredOption("--ip <ip>", "instance public ip")
.requiredOption("-n, --servername <name>", "TO4 public server name")
.requiredOption("-p, --password <password>", "TO4 server admin Password")
.action(({ ip, servername, password }) => {
console.log("provision command called");
console.table({ ip, servername, password });
commands
.provisionInstance(ip, servername, password)
.then(onSuccess)
.catch(onFail);
});
program.parse(process.argv);