forked from pinojs/pino-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·61 lines (52 loc) · 1.18 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
#! /usr/bin/env node
'use strict'
const minimist = require('minimist')
const pump = require('pump')
const fs = require('fs')
const path = require('path')
const pinoElasticSearch = require('./lib')
function start (opts) {
if (opts.help) {
console.log(fs.readFileSync(path.join(__dirname, './usage.txt'), 'utf8'))
return
}
if (opts.version) {
console.log('pino-elasticsearch', require('./package.json').version)
return
}
if (opts.username && opts.password) {
opts.auth = {
username: opts.username,
password: opts.password
}
}
if (opts['api-key']) {
opts.auth = { apiKey: opts['api-key'] }
}
if (opts.cloud) {
opts.cloud = { id: opts.cloud }
}
if (opts.rejectUnauthorized) {
opts.rejectUnauthorized = opts.rejectUnauthorized !== 'false'
}
pump(process.stdin, pinoElasticSearch(opts))
}
start(minimist(process.argv.slice(2), {
alias: {
version: 'v',
help: 'h',
node: 'n',
index: 'i',
'bulk-size': 'b',
'flush-bytes': 'f',
'flush-interval': 't',
'trace-level': 'l',
username: 'u',
password: 'p',
'api-key': 'k',
cloud: 'c'
},
default: {
node: 'http://localhost:9200'
}
}))