forked from pinojs/pino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.js
executable file
·59 lines (49 loc) · 1.34 KB
/
bin.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
#! /usr/bin/env node
'use strict'
var pretty = require('./pretty')
var fs = require('fs')
module.exports = pretty
if (arg('-h') || arg('--help')) {
usage().pipe(process.stdout)
} else if (arg('-v') || arg('--version')) {
console.log(require('./package.json').version)
} else {
process.stdin.pipe(pretty({
timeTransOnly: arg('-t'),
levelFirst: arg('-l'),
forceColor: arg('-c'),
messageKey: argWithParam('-m'),
dateFormat: argWithParam('--dateFormat'),
errorProps: paramToArray(argWithParam('--errorProps')),
errorLikeObjectKeys: paramToArray(argWithParam('--errorLikeObjectKeys')),
localTime: arg('--localTime')
})).pipe(process.stdout)
if (!process.stdin.isTTY && !fs.fstatSync(process.stdin.fd).isFile()) {
process.once('SIGINT', function noOp () {})
}
}
function usage () {
var help = require('path').join(__dirname, 'usage.txt')
return fs.createReadStream(help)
}
function arg (s) {
return !!~process.argv.indexOf(s)
}
function argWithParam (s) {
if (!arg(s)) {
return
}
var argIndex = process.argv.indexOf(s) + 1
var argValue = process.argv.length > argIndex &&
process.argv[argIndex]
if (!argValue) {
throw new Error(s + ' flag provided without a string argument')
}
return argValue
}
function paramToArray (param) {
if (!param) {
return
}
return param.split(/\s?,\s?/)
}