From 05e123b4f32da439a39502b558d50455a537ec7d Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 13 Dec 2023 21:49:39 +0100 Subject: [PATCH] Update to latest help-me (#482) --- bin.js | 138 +++++++++++++++++++++++++-------------------------- package.json | 2 +- 2 files changed, 68 insertions(+), 72 deletions(-) diff --git a/bin.js b/bin.js index 3e18d434..d9d23aea 100644 --- a/bin.js +++ b/bin.js @@ -33,84 +33,80 @@ const joycon = new JoyCon({ const cmd = minimist(process.argv.slice(2)) -helper(cmd) +if (cmd.h || cmd.help) { + help.toStdout() +} else { + const DEFAULT_VALUE = '\0default' -const DEFAULT_VALUE = '\0default' - -let opts = minimist(process.argv, { - alias: { - colorize: 'c', - colorizeObjects: 'C', - crlf: 'f', - errorProps: 'e', - levelFirst: 'l', - minimumLevel: 'L', - customLevels: 'x', - customColors: 'X', - useOnlyCustomProps: 'U', - errorLikeObjectKeys: 'k', - messageKey: 'm', - levelKey: CONSTANTS.LEVEL_KEY, - levelLabel: 'b', - messageFormat: 'o', - timestampKey: 'a', - translateTime: 't', - ignore: 'i', - include: 'I', - hideObject: 'H', - singleLine: 'S' - }, - default: { - messageKey: DEFAULT_VALUE, - minimumLevel: DEFAULT_VALUE, - levelKey: DEFAULT_VALUE, - timestampKey: DEFAULT_VALUE - } -}) - -// Remove default values -opts = filter(opts, value => value !== DEFAULT_VALUE) -const config = loadConfig(opts.config) -// Override config with cli options -opts = Object.assign({}, config, opts) -// set defaults -opts.errorLikeObjectKeys = opts.errorLikeObjectKeys || 'err,error' -opts.errorProps = opts.errorProps || '' + let opts = minimist(process.argv, { + alias: { + colorize: 'c', + colorizeObjects: 'C', + crlf: 'f', + errorProps: 'e', + levelFirst: 'l', + minimumLevel: 'L', + customLevels: 'x', + customColors: 'X', + useOnlyCustomProps: 'U', + errorLikeObjectKeys: 'k', + messageKey: 'm', + levelKey: CONSTANTS.LEVEL_KEY, + levelLabel: 'b', + messageFormat: 'o', + timestampKey: 'a', + translateTime: 't', + ignore: 'i', + include: 'I', + hideObject: 'H', + singleLine: 'S' + }, + default: { + messageKey: DEFAULT_VALUE, + minimumLevel: DEFAULT_VALUE, + levelKey: DEFAULT_VALUE, + timestampKey: DEFAULT_VALUE + } + }) -const res = build(opts) -pump(process.stdin, res) + // Remove default values + opts = filter(opts, value => value !== DEFAULT_VALUE) + const config = loadConfig(opts.config) + // Override config with cli options + opts = Object.assign({}, config, opts) + // set defaults + opts.errorLikeObjectKeys = opts.errorLikeObjectKeys || 'err,error' + opts.errorProps = opts.errorProps || '' -// https://github.com/pinojs/pino/pull/358 -/* istanbul ignore next */ -if (!process.stdin.isTTY && !fs.fstatSync(process.stdin.fd).isFile()) { - process.once('SIGINT', function noOp () {}) -} + const res = build(opts) + pump(process.stdin, res) -function loadConfig (configPath) { - const files = configPath ? [path.resolve(configPath)] : undefined - const result = joycon.loadSync(files) - if (result.path && !isObject(result.data)) { - configPath = configPath || path.basename(result.path) - throw new Error(`Invalid runtime configuration file: ${configPath}`) + // https://github.com/pinojs/pino/pull/358 + /* istanbul ignore next */ + if (!process.stdin.isTTY && !fs.fstatSync(process.stdin.fd).isFile()) { + process.once('SIGINT', function noOp () {}) } - if (configPath && !result.data) { - throw new Error(`Failed to load runtime configuration file: ${configPath}`) - } - return result.data -} -function filter (obj, cb) { - return Object.keys(obj).reduce((acc, key) => { - const value = obj[key] - if (cb(value, key)) { - acc[key] = value + function loadConfig (configPath) { + const files = configPath ? [path.resolve(configPath)] : undefined + const result = joycon.loadSync(files) + if (result.path && !isObject(result.data)) { + configPath = configPath || path.basename(result.path) + throw new Error(`Invalid runtime configuration file: ${configPath}`) } - return acc - }, {}) -} + if (configPath && !result.data) { + throw new Error(`Failed to load runtime configuration file: ${configPath}`) + } + return result.data + } -function helper (cmd) { - if (cmd.h || cmd.help) { - help.toStdout() + function filter (obj, cb) { + return Object.keys(obj).reduce((acc, key) => { + const value = obj[key] + if (cb(value, key)) { + acc[key] = value + } + return acc + }, {}) } } diff --git a/package.json b/package.json index 9dc5f8fc..ded33157 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "dateformat": "^4.6.3", "fast-copy": "^3.0.0", "fast-safe-stringify": "^2.1.1", - "help-me": "^4.0.1", + "help-me": "^5.0.0", "joycon": "^3.1.1", "minimist": "^1.2.6", "on-exit-leak-free": "^2.1.0",