New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coerce is called multiple times #1802
Comments
Hey! I believe I fixed this bug with this PR. Ben has already published this fix to I ran the following code locally (with and without the fix) and it worked correctly. No recursive calling of coerce middleware. yargs
.options({
opt: {
coerce: (opt) => {
console.log("opt coerce middleware called");
console.log(`opt: ${opt}`);
return opt;
},
},
})
.command({
command: "cmd1",
desc: "cmd1 desc",
builder: (yargs) =>
yargs
.options({
opt1: {
type: "string",
coerce: (opt1) => {
console.log("opt1 coerce middleware called");
console.log(`opt1: ${opt1}`);
return opt1;
},
},
})
.command({
command: "cmd2",
desc: "cmd2 desc",
builder: (yargs) =>
yargs.options({
opt2: {
type: "string",
coerce: (opt2) => {
console.log("opt2 coerce middleware called");
console.log(`opt2: ${opt2}`);
return opt2;
},
},
}),
handler: (argv) => {
console.log(argv);
},
}),
handler: (argv) => {
console.log(argv);
},
})
.help()
.parse("cmd1 cmd2 --opt test --opt1 test1 --opt2 test2"); logs with fix:
logs without fix:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Coerce should always be run once and only once.
The text was updated successfully, but these errors were encountered: