-
Notifications
You must be signed in to change notification settings - Fork 123
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
A coerce function runs again for each alias #76
Comments
Hey, thanks again for opening the issue. Thinking about this again, I actually think this is intended behaviour. This is because This is also why your coercion function was run for each alias. Every alias should hold the same value and just serve it under another name, so a coercion defined for an option also should be applied to all of its aliases. So finally, this behaviour is intentional, and I think you might prefer another concept to deal with your args. I would propose using commands. Here's an example of how that might look like: In the cli:
In code: yargs
.command('read <file>', // The '<file>' creates a required positional argument that does not need a flag in front of it
'read a file', {}, argv => {
console.log('reading file', argv.file);
// and so on...
})
.argv You can read more about commands here. If you have any more questions or anything else, feel free to ask! |
@maxrimue Sure, but the function doesn't need to run multiple times, just the result needs to be applied to each alias. The underlying structure of the arg/alias processing looks like it makes running the function multiple times easier than "knowing" when an arg and it's aliases have been coerced already. i.e yargs doesn't seem to track an arg and an alias as separate things, they all get put in one big blob together and linked by the Thanks for the command tip, but this is an option to a command rather than a standalone command itself. |
@maxrimue @deployable I agree that this might be worth discussing more, would be nice to potentially only apply the coerce method once. |
It even run for auto camelCased alias |
The coerce function for an argument with an alias will run multiple times, the initial run and then once more per alias.
I only noticed as I was using the file coercion example and reading a largish file.
then
from yargs/yargs#729
The text was updated successfully, but these errors were encountered: