-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommandline.js
51 lines (41 loc) · 1.31 KB
/
commandline.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
/*
* -------------------------------------------------------------------------------
* commandline.js
*
* Configures and processes command line arguments and exports the configuration
* found therein as well as the name of the configuration file, if found.
* -------------------------------------------------------------------------------
*/
'use strict'
const fs = require('fs')
, path = require('path')
, program = require('commander')
let cfgFileName = ''
, cfg = {}
const getAppName = () => {
return 'Midwife-EMR'
}
const getVersion = () => {
return fs.readFileSync(path.join(__dirname, './VERSION'))
}
// --------------------------------------------------------
// Process command-line parameters.
// --------------------------------------------------------
program
.version(getAppName() + ' version ' + getVersion())
.option('-c, --config <path>', 'Specify configuration file')
.parse(process.argv)
// --------------------------------------------------------
// Load the configuration file, if available.
// --------------------------------------------------------
if (program.config && program.config.length > 0) {
cfgFileName = program.config
try {
const contents = fs.readFileSync(cfgFileName)
cfg = JSON.parse(contents)
} catch (e) { }
}
module.exports = {
cfgFileName,
cfg
}