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

Layering env, args, and config #3113

Open
epage opened this issue Dec 9, 2021 · 7 comments
Open

Layering env, args, and config #3113

epage opened this issue Dec 9, 2021 · 7 comments
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing

Comments

@epage
Copy link
Member

epage commented Dec 9, 2021

Maintainer's note


Issue by synek317
Monday Feb 19, 2018 at 10:02 GMT
Originally opened as TeXitoi/structopt#72


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.

@epage
Copy link
Member Author

epage commented Dec 9, 2021

Comment by TeXitoi
Monday Feb 19, 2018 at 13:40 GMT


You might be interested in TeXitoi/structopt#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.

@epage
Copy link
Member Author

epage commented Dec 9, 2021

Comment by synek317
Monday Feb 19, 2018 at 13:46 GMT


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.

@epage
Copy link
Member Author

epage commented Dec 9, 2021

Comment by TeXitoi
Monday Feb 19, 2018 at 13:59 GMT


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

@epage
Copy link
Member Author

epage commented Dec 9, 2021

Comment by TeXitoi
Wednesday Feb 21, 2018 at 14:53 GMT


@synek317 ping

@epage
Copy link
Member Author

epage commented Dec 9, 2021

Comment by synek317
Friday Feb 23, 2018 at 16:42 GMT


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.

@epage
Copy link
Member Author

epage commented Dec 9, 2021

Comment by synek317
Monday Mar 05, 2018 at 04:50 GMT


@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/ ?

@epage epage changed the title Feature-gated config-rs handling Config layering Dec 9, 2021
@epage epage added the C-enhancement Category: Raise on the bar on expectations label Dec 9, 2021
@epage
Copy link
Member Author

epage commented Dec 9, 2021

See also #2763

@epage epage changed the title Config layering Layering env, args, and config Dec 10, 2021
@epage epage added A-parsing Area: Parser's logic and needs it changed somehow. S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing labels Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing
Projects
None yet
Development

No branches or pull requests

1 participant