-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
25 lines (22 loc) · 729 Bytes
/
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
#!/usr/bin/env node
var ApcAccess = require('./lib/apcaccess');
var cli = require('cli');
var options = cli.parse({
host: ['H', 'Hostname or ip address of the apcupsd nis', 'string', 'localhost'],
port: ['p', 'Port of the apcupsd nis', 'int', 3551]
},
['status', 'statusJson', 'events']);
var apcaccess = new ApcAccess();
apcaccess.connect(options.host, options.port)
.then(function() {
if(cli.command === 'status') return apcaccess.getStatus();
else if(cli.command === 'statusJson') return apcaccess.getStatusJson();
else if(cli.command === 'events') return apcaccess.getEvents();
})
.then(function(result) {
console.log(result);
return apcaccess.disconnect();
})
.catch(function(err) {
console.log(err);
});