-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreach-cli.js
More file actions
69 lines (54 loc) · 1.67 KB
/
reach-cli.js
File metadata and controls
69 lines (54 loc) · 1.67 KB
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
const { Command } = require("commander");
const { Reach } = require("./reach");
const program = new Command();
Reach.init();
program
.name("Reach SDK CLI")
.description("CLI to send notifications easily using the Reach SDK")
.version("0.0.1");
program.command("list")
.description("Prints a list of the supported providers")
.action(() => {
console.log(Reach.listProviders());
});
program.command("arguments")
.description("Display the required and optional arguments for a supported provider")
.argument("Provider", "")
.action((str) => {
console.log("Arguments for: " + str);
console.log(Reach.parameters(str));
});
addProvidersAndOptions();
function addProvidersAndOptions() {
// List and add all providers and their options
var providers = Reach.listProviders();
providers.forEach(provider => {
var send = program.command(provider);
var args = Reach.parameters(provider);
Object.keys(args["required"]).forEach(function(key) {
send.requiredOption("--" + key + " <value> ", "Required");
});
Object.keys(args["optional"]).forEach(function(key) {
send.option("--" + key + " <value>", "");
});
send.action(() => {
console.log("Sending " + provider);
var requiredOpts = {};
var optionalOpts = {};
send.options.forEach(option => {
if (option.mandatory) {
requiredOpts[option.long.substring(2)] = send.getOptionValue(option.long.substring(2));
} else {
optionalOpts[option.long.substring(2)] = send.getOptionValue(option.long.substring(2));
}
});
const notification = {
name: provider,
required:requiredOpts,
optional: optionalOpts
};
console.log(Reach.send(notification));
});
});
}
program.parse();