forked from gtorodelvalle/fiware-device-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiwareDeviceSimulatorCLI
More file actions
executable file
·102 lines (84 loc) · 2.89 KB
/
fiwareDeviceSimulatorCLI
File metadata and controls
executable file
·102 lines (84 loc) · 2.89 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env node
/*
* Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U
*
* This file is part of the Short Time Historic (STH) component
*
* STH is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* STH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with STH.
* If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by the GNU Affero General Public License
* please contact with: [german.torodelvalle@telefonica.com]
*/
'use strict';
var ROOT_PATH = require('app-root-path');
var commander = require('commander');
var logops = require('logops');
var deviceSimulator = require(ROOT_PATH + '/lib/fiwareDeviceSimulator');
process.on('SIGINT', function() {
deviceSimulator.stop();
process.exit(0);
});
/**
* Executes the requested commander
*/
function executeCommand() {
if (!commander.configuration) {
commander.help();
}
var configurationFilePath;
if (commander.configuration[0] === '/') {
configurationFilePath = commander.configuration;
} else if (commander.configuration[0] === '.') {
configurationFilePath = ROOT_PATH + commander.configuration.substring(1);
} else {
commander.help();
}
var progressEmitter = deviceSimulator.start(require(configurationFilePath));
progressEmitter.on('token-request', function() {
logops.info('token-request event');
});
progressEmitter.on('token-response', function(ev) {
logops.info('token-response event:', ev);
});
progressEmitter.on('token-request-scheduled', function(ev) {
logops.info('token-request-scheduled:', ev);
});
progressEmitter.on('update-scheduled', function(ev) {
logops.info('update-scheduled event:', ev);
});
progressEmitter.on('update-request', function(ev) {
logops.debug('update-request event:', ev);
});
progressEmitter.on('error', function(ev) {
logops.error('error event:', ev);
});
progressEmitter.on('update-response', function(ev) {
logops.debug('response event:', ev);
});
progressEmitter.on('stop', function() {
logops.info('stop event');
});
progressEmitter.on('end', function() {
logops.info('end event');
process.exit(0);
});
}
commander.
version(require(ROOT_PATH + '/package.json').version).
option('-c, --configuration <configuration-file-path>',
'Absolute or relative path (from the root of the Node application) to the device simulator configuration file ' +
'(mandatory)').
parse(process.argv);
executeCommand();