Yargs :在失败函数中访问已处理的 argv



我使用yargs作为复杂的命令行(通过commandDir使用子命令(。 我想使用 .fail(fn( 在每次给定命令失败时发送电子邮件。.fail(fn( 被正确触发,但我希望能够访问提供给命令的参数。.fail(fn( 只允许我访问 msg, err, yargs。

require('yargs')
.commandDir('commands', {recurse: false})
.option('verbose', {
alias: 'v',
type: 'boolean',
description: 'Run with verbose logging',
default: false
})
.option('senderr', {
alias: 'se',
type: 'boolean',
description: 'Send error(s) via email',
default: true
})
.demandCommand()
.help()
.fail(function (msg, err, yargs) {
console.log(err);
process.exit(1);
})
.locale('fr')
.argv

是否可以在失败函数中访问 argv.senderr 值? 谢谢!

我遇到了同样的问题,似乎没有当前的解决方案,但是我最近发布了一个github问题:https://github.com/yargs/yargs/issues/2133

const argv = require('yargs')
.commandDir('commands', {recurse: false})
.option('verbose', {
alias: 'v',
type: 'boolean',
description: 'Run with verbose logging',
default: false
})
.option('senderr', {
alias: 'se',
type: 'boolean',
description: 'Send error(s) via email',
default: true
})
.demandCommand()
.help()
.fail(function (msg, err, yargs) {
if (argv.verbose) console.log(err);
process.exit(1);
})
.locale('fr')
.argv

最新更新