-
Notifications
You must be signed in to change notification settings - Fork 8
/
service_list.js
35 lines (31 loc) · 923 Bytes
/
service_list.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
const { Service } = require('./service');
const { ShellCommand } = require('./shell_command');
class ServiceList {
constructor (rootElement) {
this.rootElement = rootElement;
}
clear () {
this.rootElement.innerHTML = '';
}
load () {
ShellCommand.run('brew', ['services', 'list'], (output) => {
const lines = output.toString().split('\n');
lines.shift();
lines.pop();
this.clear();
if (lines.length > 0) {
lines.forEach((line) => {
const parts = line.split(/\s+/);
const service = new Service(parts[0], parts[1]);
service.draw(this.rootElement);
});
} else {
const tip = document.createElement('LI');
const tipText = document.createTextNode('No available service');
tip.appendChild(tipText);
this.rootElement.appendChild(tip);
}
});
}
}
exports.ServiceList = ServiceList;