Skip to content

Commit 29127db

Browse files
committed
refactor: migrate to commander 12
1 parent e854fe0 commit 29127db

File tree

3 files changed

+24
-33
lines changed

3 files changed

+24
-33
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"checks": "pnpm typecheck && pnpm lint && pnpm test"
5959
},
6060
"dependencies": {
61-
"commander": "^10.0.1",
61+
"commander": "^12.0.0",
6262
"got": "^11.8.6",
6363
"pino-abstract-transport": "^1.2.0",
6464
"pump": "^3.0.0"

pnpm-lock.yaml

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

+17-26
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,28 @@ import build from './index'
55
import pkg from '../package.json'
66
import type { LokiOptions } from './types/index'
77

8-
/**
9-
* Parse cli arguments with commander
10-
*/
11-
export const parseArgs = () => {
12-
program
13-
.version(pkg.version)
14-
.option('-u, --user <user>', 'Loki username')
15-
.option('-p, --password <password>', 'Loki password')
16-
.option('--hostname <hostname>', 'URL for Loki')
17-
.option('-b, --batch', 'Should logs be sent in batch mode')
18-
.option('-i, --interval <interval>', 'The interval at which batched logs are sent in seconds')
19-
.option('-t, --timeout <timeout>', 'Timeout for request to Loki')
20-
.option('-s, --silenceErrors', 'If false, errors will be displayed in the console')
21-
.option('-r, --replaceTimestamp', 'Replace pino logs timestamps with Date.now()')
22-
.option('-l, --labels <label>', 'Additional labels to be added to all Loki logs')
23-
.option(
24-
'-pl, --propsLabels <labels>',
25-
'Fields in log line to convert to Loki labels (comma separated values)',
26-
)
27-
.option('--no-stdout', 'Disable output to stdout')
28-
29-
program.parse(process.argv)
30-
31-
return program.opts()
32-
}
8+
program
9+
.version(pkg.version)
10+
.option('-u, --user <user>', 'Loki username')
11+
.option('-p, --password <password>', 'Loki password')
12+
.option('--hostname <hostname>', 'URL for Loki')
13+
.option('-b, --batch', 'Should logs be sent in batch mode')
14+
.option('-i, --interval <interval>', 'The interval at which batched logs are sent in seconds')
15+
.option('-t, --timeout <timeout>', 'Timeout for request to Loki')
16+
.option('-s, --silenceErrors', 'If false, errors will be displayed in the console')
17+
.option('-r, --replaceTimestamp', 'Replace pino logs timestamps with Date.now()')
18+
.option('-l, --labels <label>', 'Additional labels to be added to all Loki logs')
19+
.option(
20+
'-pl, --propsLabels <labels>',
21+
'Fields in log line to convert to Loki labels (comma separated values)',
22+
)
23+
.option('--no-stdout', 'Disable output to stdout')
3324

3425
/**
3526
* Create a PinoLokiOptionsContract from cli arguments
3627
*/
3728
export const createPinoLokiConfigFromArgs = () => {
38-
const opts = parseArgs()
29+
const opts = program.parse(process.argv).opts()
3930

4031
const config: LokiOptions = {
4132
host: opts.hostname,

0 commit comments

Comments
 (0)