-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathapi.js
More file actions
52 lines (49 loc) · 1.56 KB
/
Copy pathapi.js
File metadata and controls
52 lines (49 loc) · 1.56 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
import APIs from '../lib/paystack/apis.js';
import * as helpers from '../lib/helpers.js';
let commands = Object.keys(APIs);
const init = () => {
commands.forEach((command) => {
let section = APIs[command];
let vorp = vorpal
.command(command + ' <command>', helpers.getDescription(section, command))
.validate(function (args) {
let selected_integration = db.read('selected_integration')['id'];
let user = db.read('user')['id'];
if (!selected_integration || !user) {
helpers.errorLog(
"You're not signed in, please run the `login` command before you begin"
);
return false;
}
})
.action(async function (args, callback) {
let schema = JSON.parse(
JSON.stringify(helpers.findSchema(command, args))
);
let [err, result] = await helpers.promiseWrapper(
helpers.executeSchema(schema, args)
);
if (err) {
if (err.response) {
helpers.errorLog(err.response.data.message);
return;
}
helpers.errorLog(err);
return;
}
helpers.successLog(result.message);
helpers.jsonLog(result.data);
});
vorp.option('--domain <value>', ' ');
let added_options = ['domain'];
section.forEach((f) => {
f.params.forEach((o) => {
if (added_options.indexOf(o.parameter) < 0) {
vorp.option('--' + o.parameter + ' <value> ', ' ');
added_options.push(o.parameter);
}
});
});
});
};
export default init;