-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevice.js
65 lines (55 loc) · 1.44 KB
/
device.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
var deps = { }
const macactions = {
poe: "./poe_mode"
};
const actions = {
ls: "./device/ls"
}
var activeactions;
function deviceRelay(called, argv) {
var action = argv._.splice(0, 1)[0]
called += ' device';
if (isMac(action)) {
called += ` ${action}`
argv.mac = action;
action = argv._.splice(0, 1)[0]
activeactions = macactions;
doAction(action, called, argv);
return
}
activeactions = actions;
doAction(action, called, argv);
}
function showHelp() {
}
function isMac(action) {
if (action !== undefined
&& action.length == 17
&& action.split(':').length == 6
) {
return true;
}
return false;
}
function doAction(action, called, argv) {
if (activeactions[action] === undefined) {
console.log(`Usage: device <action>`);
console.log(`Usage: device <mac address> <action>`);
console.log(`Supported actions: ${Object.keys(actions).join(', ')}`);
console.log(`Supported MAC address actions: ${Object.keys(macactions).join(', ')}`);
return;
}
activeactions[action] = require(activeactions[action]);
if(activeactions[action].deps !== undefined) {
Object.assign(activeactions[action].deps, deps);
}
activeactions[action].func(called, argv);
}
function doMACAction(action, called, argv) {
}
module.exports = {
login: true,
func: deviceRelay,
deps: deps
}