Skip to content
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

Pass the name of the property being assigned to the custom coerce function #262

Closed
mojavelinux opened this issue Jul 4, 2018 · 7 comments

Comments

@mojavelinux
Copy link
Contributor

Pass the name of the property to which the value is being prepared to the custom coerce function. This will allow the function to look up the old value and append the new value to it instead of overwriting it. This can be useful for config properties that hold a collection of data.

Example:

coerce: (val, config, name) => { 
  const accum = config.get(name)
  const [k, v] = val.split('=')
  accum[k] = v
  return accum
}

The main use case for this is binding the config property to an argument that can be specified multiple times from command-line (e.g., --attribute key=val).

@madarche
Copy link
Collaborator

madarche commented Jul 4, 2018

Hello @mojavelinux. Presently my time is too short to be able to calmly think on issues. So please could you elaborate a bit more: are you requesting approval on a proposed change before submitting the corresponding PR?

@mojavelinux
Copy link
Contributor Author

Correct. I am floating the idea before I commit time to implementing it. This feature would be really useful for the project I'm working on that uses convict for config.

@madarche
Copy link
Collaborator

madarche commented Jul 4, 2018

OK. I'll take time to think about it and will report back here. Don't hesitate to invite other active users of convict into the discussion!

@mojavelinux
Copy link
Contributor Author

This seems to be a pretty low-impact change because we're simply adding another optional argument for the coerce function to accept.

@madarche
Copy link
Collaborator

madarche commented Jul 4, 2018

Understood.

mojavelinux added a commit to mojavelinux/node-convict that referenced this issue Jul 5, 2018
@mojavelinux
Copy link
Contributor Author

I sent a PR.

@A-312
Copy link
Contributor

A-312 commented Dec 7, 2019

I thought coerce function was only to convert value/format not change value depending of dynamic value but this commit is a good hack instead getter (#313). :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants