-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcli.js
51 lines (39 loc) · 1.29 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
// Import config. (Thanks @Ernie3 for adding this!)
const config = require('./config.json')
// Import libraries.
const logger = require('./logger.js')
const hhmmss = require('./hhmmss.js')
// CLI prepper.
exports.initCli = function() {
// Prepare stdin.
logger.info('Initializing console commands...')
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', function (text) {
// Prep command.
var command = text.trim()
if (command[0] === '/') {
// Command: /help
if (command === '/help') {
logger.data('COMMANDS: help quit config uptime')
// Command: /quit
} else if (command === '/quit') {
logger.warn('Quit requested, exiting now...')
process.exit()
// Command: /config
} else if (command === '/config') {
logger.data('CONFIG: App on port ' + config.port + '.')
// Command: /uptime
} else if (command === '/uptime') {
logger.data('UPTIME: ' + hhmmss.toHHMMSS(process.uptime()+""))
// Invalid command.
} else {
logger.error('Invalid command.')
}
// No command.
} else {
logger.data('ECHO: ' + command)
}
})
logger.state('Console ready, run \"/help\" to list commands.')
}