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

Feature-gated config-rs handling #72

Closed
synek317 opened this issue Feb 19, 2018 · 7 comments
Closed

Feature-gated config-rs handling #72

synek317 opened this issue Feb 19, 2018 · 7 comments
Labels
enhancement We would love to have this feature! Feel free to supply a PR need-design The concrete desing is uncertain, please get involved in the discussion before sending a PR

Comments

@synek317
Copy link

There is great config-rs crate that provides hierarchical configuration and deserialization into struct. I think it would be great if clap / structopt could handle feature like this. With this, one can handle app configuration that can be provided in multiple config files and/or command line all in one place and with single structure.

I suggest to add from_opts_and_config function that would accept Config instance (from config-rs) that would provide defaults when argument is not passed in command line.

I think that it is a best way because only structopt has full knowledge if and what arguments has been passed and which are mandatory and what should be default value if arg is not passed. Config crate requires that all values are defined, otherwise deserialization returns Err.

Of course config-rs dependency should be configurable with features.

If you think it is a good idea, I could prepare some implementation.

@TeXitoi TeXitoi added the enhancement We would love to have this feature! Feel free to supply a PR label Feb 19, 2018
@TeXitoi
Copy link
Owner

TeXitoi commented Feb 19, 2018

You might be interested in #32

StructOpt is just a wrapper above clap. Looking at your proposition, it seems better to include this functionality directly in clap. But you may have some arguments to do it in structopt.

@synek317
Copy link
Author

I have done a sketch implementation and it is very simple to use config-rs in StructOpt. However, that is not really a great argument.

@TeXitoi
Copy link
Owner

TeXitoi commented Feb 19, 2018

You can point to a branch, and I'll look a it to seen what is your idea.

@TeXitoi
Copy link
Owner

TeXitoi commented Feb 21, 2018

@synek317 ping

@synek317
Copy link
Author

After some tries I think that there is a better way to solve this. Clap has 'default_value' attrs. If it could be 'default_value_fn' then merging config from file(s) with command line args could be done by 3rd party lib.

@synek317
Copy link
Author

synek317 commented Mar 5, 2018

@TeXitoi Could you please take a look at my solution sketch at https://www.reddit.com/r/rust/comments/81tp16/wip_platformconfig_multisource_configuration_for/ ?

@TeXitoi
Copy link
Owner

TeXitoi commented Jan 18, 2022

This is an enhancement, and structopt is now feature frozen.

@TeXitoi TeXitoi closed this as completed Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement We would love to have this feature! Feel free to supply a PR need-design The concrete desing is uncertain, please get involved in the discussion before sending a PR
Projects
None yet
Development

No branches or pull requests

2 participants