forked from robson83/augustctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·37 lines (29 loc) · 869 Bytes
/
cli.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
36
37
#!/usr/bin/env node
'use strict';
const augustctl = require('./index');
const util = require('util');
const fs = require('fs').promises;
async function main() {
const configPath = process.env.AUGUSTCTL_CONFIG || './config.json';
const config = JSON.parse(await fs.readFile(configPath, 'utf8'));
const operation = process.argv[2];
const lockPrototype = Object.getPrototypeOf(new augustctl.Lock());
if (typeof lockPrototype[operation] !== 'function') {
throw new Error('Invalid operation: ' + operation);
}
try {
const peripheral = await augustctl.scan(config.lockUuid);
const lock = new augustctl.Lock(
peripheral,
config.offlineKey,
config.offlineKeyOffset
);
await lock.connect();
await lock[operation]();
} catch (e) {
console.error(e.toString());
} finally {
process.exit(0);
}
}
main();