我试图让失踪的用户参与进来,需要一种动力/强制性选择。
我认为,我可以迅速使用一个前线,即修改<代码>程序.argv,然后允许指挥官将经过更新的遗体划入。
然而,在我ook的背心之后,我会发现这一错误:<代码>ror:要求选择——没有具体规定的<<>/code>。
看来,在老进程 h后,教 par继续。
For example my-cli subcommand --foo bar
will work fine.
my-cli subcommand
will prompt for foo
and push it to process.argv
inside the hook but then exit with the error above.
Any ideas? I tried to suppress this error with exitOverride
and re-calling parse
afterwards, but my callback is not being reached. Surrounding in try-catch doesn t work either.
Here s my code:
program
.name( cli )
.description( foo )
.version(version, -v, --version )
.addCommand(sub)
.hook( preSubcommand , async (program, subcommand) => {
await promptForMissingArgs(program, subcommand);
console.log( here );
console.log(process.argv);
program.parse(process.argv); // called again with correct process.argv but still exits
})
.exitOverride((exitCode) => {
console.log(`Exiting with code ${exitCode.exitCode}`); // not reached
// if (exitCode.exitCode !== 0) {
// program.parse(process.argv);
// }
});
// parse command line arguments and execute command
try {
program.parse(process.argv);
} catch (error) {
console.log( here ); // doesn t reach here
console.error(error);
}
From the docs I see this: if the first arg is a subcommand call preSubcommand hooks pass remaining arguments to subcommand, and process same way
https://github.com/tj/commander.js/blob/HEAD/docs/parsing-and-hooks.md
这是否是因为我的 h是同yn?