-
Notifications
You must be signed in to change notification settings - Fork 4
/
execute
executable file
·59 lines (50 loc) · 1.44 KB
/
execute
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
#!/usr/bin/env node
const dnode = require('dnode');
const Promise = require('bluebird');
const inquirer = require('inquirer');
let client;
function init() {
return new Promise((resolve, reject) => {
try {
client = dnode.connect(9090);
} catch(e) {
return reject(e);
}
client.on('error', (err) => {
throw err;
});
client.on('remote', (remote) => {
return resolve(remote);
});
});
}
init()
.then((api) => {
api.getTasks((err, tasks) => {
if (err) {
throw err;
}
return inquirer.prompt([
{
'message': 'Select the task to execute',
'name': 'id',
'type': 'list',
'choices': tasks.map((task) => {
return {
'name': task.title,
'value': task.id
};
})
}
])
.then(({ id }) => {
api.execute(id, (err) => {
if (err) {
throw err;
}
console.log(`Task is executing.`);
process.exit(0);
});
});
});
});