-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
62 lines (51 loc) · 1.75 KB
/
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
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
require( 'dotenv' ).config();
const yargs = require( 'yargs' );
const argv = yargs
.option( 'serialport', {
alias: 's',
description: 'Serial port your controller is connected to (e.g -s /dev/ttyUSB0)',
type: 'string',
})
.option( 'baudrate', {
alias: 'b',
description: 'The baud rate to use for serial communications',
type: 'integer',
default: 9600
})
.option( 'device', {
alias: 'd',
description: 'The device ID (valid from 1 to 247)',
type: 'integer',
default: 1
})
.option( 'address', {
alias: 'a',
description: 'The local address on which to serve HTTP requests',
type: 'string',
default: 'localhost'
})
.option( 'tcpport', {
alias: 'p',
description: 'The TCP port on which to publish the Prometheus metrics',
type: 'integer',
default: 9090
})
.option( 'loglevel', {
alias: 'l',
description: 'Logging level to use',
type: 'string',
default: 'info'
}).choices( 'loglevel', [ 'trace', 'debug', 'info', 'warn', 'error', 'fatal' ] )
.help().alias( 'help', 'h' )
.version().alias( 'version', 'v' )
.epilogue( 'Environment variables set as SR_{OPTION} will be used to set options. They can also be set in:' )
.epilogue( ` ${__dirname}/.env` )
.epilogue( '' )
.epilogue( 'For more information, see https://github.com/MaffooClock/SerialRenogy' )
.env( 'SR' )
.demandOption( 'serialport', 'Serial port not specified' )
.wrap( Math.min( yargs.terminalWidth(), 120 ) )
.argv;
module.exports = {
args: argv
};