-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Expected Behavior
According to https://github.com/tj/commander.js/blob/master/Readme.md#action-handler, .parseAsync() should be used for async action handlers.
Actual Behavior
If a subcommand uses an async action handler, program.parse() also works.
const makeBuildCommand = () => {
const program = new Command('build');
program.argument('<path>').action(async (path) => {
await new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Path: ' + path);
resolve();
}, 1000);
});
console.log('Action Handler completed');
});
return program;
};
const init = () => {
const program = new Command();
program.addCommand(makeBuildCommand());
program.parse(process.argv);
};
try {
init();
} catch (error) {
console.error(error);
}
Is this expected behavior? Since both .parse() and .parseAsync() work in this case, which variant is recommended?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels