-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Consider changing clap to configure_me #9
Comments
Thanks for suggestion! I've been seeing What I'd like to consider before adopting it. The current model that we follow — to adopt command-line options + environment using (yet unreleased) Clap 3.0 with custom derive — you may see how it works in https://github.com/LNP-BP/lnp-node/blob/aa20f431fd5f6753049eb45011b1c04b1b048daa/src/wired/config.rs#L23-L54: quite rust-native way, without pre-build code generation. However, with this, we have config file yet uncovered: https://github.com/LNP-BP/lnp-node/blob/aa20f431fd5f6753049eb45011b1c04b1b048daa/src/bin/wired.rs#L26 While it would be good to cover this via In general, I did differentiate May you consider the next version of |
Yeah, the issue of derives came from several people several times. I'd definitely love to do it using derives, there's even an issue still open: Kixunil/configure_me#3 I currently see these obstacles around man page generation and other tooling (there's experimental
I'm quite sad about this situation as I'd love to see less boilerplate (build.rs, which fortunately is currently only 3 lines), and proper IDE support. But considering the issues above, using toml seems to be a more useful trade-off to me. I hope you can see the reasons now. If you have a solution, I definitely want to know about it. Regarding reducing the amount of generated code, what changes would you like to see? I guess I could move a bit more stuff into shared library, but I don't see how to achieve significant reduction. Most of the complexity comes from making sure that each field has a strong rustic type and well-understandable, human-readable error messages. I'm a huge fan of strong types and they were one of the primary design goals (clap had only stringly API when I started writing |
@Kixunil Let's do it! I am persuaded. Let's change Clap in Will much appreciate a PR! |
Great, I plan to look t it soon. Having |
So I have something that passes typecheck. I have some linker errors so I can't test it yet. But anyway, there's one more issue:
? |
I think we can ignore connect for now and bring it back later when configure_me will support arrays from cli args |
This implements basic changes to use `configure_me` instead of `clap` for managing the configuration. This instantly allows us to pull the configuration from files, directories containing files and to generate man pages or other integrations that will be developed in `configure_me` in the future. So far, this is missing `connect` because it wasn't used and `configure_me` doesn't support parsing multiple arguments into arrays yet. Closes LNP-WG#9
When writing Kixunil/configure_me#38 I realized there's a quite easy workaround for multiple arguments - by making a wrapper implementing If you like this approach, I can write it. |
It seems fine, however not sure what did you mean by "instead of replacing file configuration with arguments, it'd only extend it". Does it mean that current version can use only config file or args, and not both of them? Even if yes, for sure it would be better to move to merge procedure |
It can, the difference is what happens if an option is set in config file and arg. Normally arg will just overwrite whatever is int the file, but with custom fn merge_vec(mut a: Vec<String>, b: Vec<String>) -> Vec<String> {
a.extend(b);
a
} And this will cause the vecs to merge. This is handy in some scenarios (e.g. |
This change implements the connect argument that can be repeated multiple times thanks to custom `merge_fn` as described in LNP-WG#9. It depends on recent changes to rust-lnpbp to enble serde support for `NodeAddr` and, ideally, stringly (de)serialization for better user experience. [ci skip]
I implemented it. Was pretty easy, but required better support in |
I noticed there's a bunch of code manually implementing conversions between different config structs. Also, I don't see where
config
field ofOpts
is used. Is it used at all?My crate
configure_me
happens to deal with all the complexities of loading the configuration from one or more files, environment variables and arguments and merging it as appropriate. It was developed mainly with long-running daemons in mind (that's why it currently lacks subcommands, but has a good support for config files), so it might be more suitable for a project like this. It was also successfully used inelectrs
.I also plan for it to support interface files which, if proven, should make connecting daemons such as this one to other services (most notably
bitcoind
) very easy.As the author of
configure_me
, I'm willing to do the PR, just asking beforehand to not waste time if you don't find it interesting. I noticed this crate has a cli tool that uses subcommands, so maybe I will have to implement subcommand support first, unless you're fine with doing it manually at first.The text was updated successfully, but these errors were encountered: