You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to output help from the code and not have my script die, but I'm running into the following via node run.js help run:
Code:
const { Command } = require('commander');
const program = new Command('test');
async function run() { process.stdout.write('i am running') }
async function main() {
program
.command('run')
.exitOverride()
.action(run);
await program.parseAsync(process.argv);
}
try {
main()
} catch (e) {
console.log(e);
}
I get the following error:
sage: test run [options]
Options:
-h, --help display help for command
/Users/foobar/projects/crypto-slack-ops/node_modules/commander/lib/command.js:449
this._exitCallback(new CommanderError(exitCode, code, message));
^
CommanderError: (outputHelp)
at Command._exit (/Users/foobar/projects/crypto-slack-ops/node_modules/commander/lib/command.js:449:26)
at outputHelpIfRequested (/Users/foobar/projects/crypto-slack-ops/node_modules/commander/lib/command.js:2096:9)
at Command._parseCommand (/Users/foobar/projects/crypto-slack-ops/node_modules/commander/lib/command.js:1247:5)
at /Users/foobar/projects/crypto-slack-ops/node_modules/commander/lib/command.js:1063:27
at Command._chainOrCall (/Users/foobar/projects/crypto-slack-ops/node_modules/commander/lib/command.js:1159:12)
at Command._dispatchSubcommand (/Users/foobar/projects/crypto-slack-ops/node_modules/commander/lib/command.js:1059:23)
at Command._parseCommand (/Users/foobar/projects/crypto-slack-ops/node_modules/commander/lib/command.js:1236:19)
at Command.parseAsync (/Users/foobar/projects/crypto-slack-ops/node_modules/commander/lib/command.js:917:16)
at main (/Users/foobar/projects/crypto-slack-ops/src/run.js:11:17)
at Object.<anonymous> (/Users/foobar/projects/crypto-slack-ops/src/run.js:14:1) {
code: 'commander.helpDisplayed',
exitCode: 0,
nestedError: undefined
}
Node.js v18.6.0```
The text was updated successfully, but these errors were encountered:
If you want to turn process.exit() into throws, I recommend you call program.exitOverride() before adding any commands, so they all get the setting.
However, the most direct issue is you need a different pattern to unify catching throws from async routines. Try this and ask more questions about Commander behaviour if needed:
I'm trying to output help from the code and not have my script die, but I'm running into the following via
node run.js help run
:Code:
I get the following error:
The text was updated successfully, but these errors were encountered: