Repository navigation
Add derive macros to cli config - #684
thebrandonlucas wants to merge 13 commits into
Conversation
This WIP commit begins refactoring to use the derive macros provided by clap to replace the builder method for maintainability and ease of use.
|
I do see that derive macros could save us some maintenance, but I'm not sure how to incorporate the macros on the config that also takes in toml. It would be much easier to evaluate if the proof of concept compiled. The main problem with our Config at the moment seems that it's overloaded to parse toml and merge args with that toml. It's possible that the Arg derive macros belong on the My biggest priority with the config is to make misuse inexpressible, then to report errors beautifully, then to be DRY. In my experience code with the clearest semantics tends to be the easiest to maintain, most beautiful, and most DRY as an unintended consequence. |
`VersionConfig` is part of the config but not actually an argument, and breaks compilation because it was being treated as an argument. Added the #[arg(skip)] macro to fix that. Also, updated the outdated `#[clap(flatten)]` macro in favor of the `#[command(flatten)]` macro.
Pull Request Test Coverage Report for Build 14908012592Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
This is a WIP commit to get things to a compiling state. Running with `--help` works, but full functionality is not yet restored
Performs some cleanup, more accurate commenting, and renames builder to config to more accurately make the distinction between what is being passed via cli and config file
WIP - introduce concept of a RawConfig and ValidatedConfig. Derived from concept TomlConfig and ResolvedConfig in [this](https://youtu.be/qfknfCsICUM?feature=shared&t=2135) video.
Currently, payjoin-cli parses the command line args, then conditionally overrides the config file with each that are present, and validation occurs "along the way" while parsing and adding default values from the config file. This method means the configuration code is tightly coupled. This commit begins splitting the cli parsing and config file parsing into two separate steps, with the plan to validate and override config values with cli values as a separate third step.
Adds validated versions of RawBitcoindConfig, and raw version configs.
Update version related feature flagged code and remove the determine_version code as it is no longer necessary with the removal of the .version field in ValidatedConfig
I wasn't setting bip78/bip77 error message defaults anywhere in the config. So when I didn't pass that in the cli it would break.
./contrib/lint.sh was revealing two lint errors, one caused by a missing "v2" feature flags for the OhttpKeys struct, another caused by passing the 'config' crate to the app rather than the 'validated_config' struct as a result of a missed variable rename.
|
Closing this exploratory draft in favor of #703 |
Refactors the code to use derive macros over the "legacy" builder method as per `clap`'s recommendation. The macros allow the code to be more maintainable, readable, and reusable moving forward. See[here](https://docs.rs/clap/latest/clap/_faq/index.html#when-should-i-use-the-builder-vs-derive-apis) for more details on derive vs builder method rationales. Discussion preceding this PR in payjoin#684 and [here](#1)
Refactors the code to use derive macros over the "legacy" builder method as per `clap`'s recommendation. The macros allow the code to be more maintainable, readable, and reusable moving forward. See [here](https://docs.rs/clap/latest/clap/_faq/index.html#when-should-i-use-the-builder-vs-derive-apis) for more details on derive vs builder method rationales. Discussion preceding this PR in payjoin#684 and [here](#1)
Refactors the code to use derive macros over the "legacy" builder method as per `clap`'s recommendation. The macros allow the code to be more maintainable, readable, and reusable moving forward. See [here](https://docs.rs/clap/latest/clap/_faq/index.html#when-should-i-use-the-builder-vs-derive-apis) for more details on derive vs builder method rationales. Discussion preceding this PR in payjoin#684 and [here](#1)
Refactors the code to use derive macros over the "legacy" builder method as per `clap`'s recommendation. The macros allow the code to be more maintainable, readable, and reusable moving forward. See [here](https://docs.rs/clap/latest/clap/_faq/index.html#when-should-i-use-the-builder-vs-derive-apis) for more details on derive vs builder method rationales. Discussion preceding this PR in payjoin#684 and [here](#1)
Refactors the code to use derive macros over the "legacy" builder method as per `clap`'s recommendation. The macros allow the code to be more maintainable, readable, and reusable moving forward. See [here](https://docs.rs/clap/latest/clap/_faq/index.html#when-should-i-use-the-builder-vs-derive-apis) for more details on derive vs builder method rationales. Discussion preceding this PR in payjoin#684 and [here](#1)
Refactors the code to use derive macros over the "legacy" builder method as per `clap`'s recommendation. The macros allow the code to be more maintainable, readable, and reusable moving forward. See [here](https://docs.rs/clap/latest/clap/_faq/index.html#when-should-i-use-the-builder-vs-derive-apis) for more details on derive vs builder method rationales. Discussion preceding this PR in payjoin#684 and [here](#1)
Refactors the code to use proc macros over the "legacy" builder method as per `clap`'s recommendation. The macros allow the code to be more maintainable, readable, and reusable moving forward. See [here](https://docs.rs/clap/latest/clap/_faq/index.html#when-should-i-use-the-builder-vs-derive-apis) for more details on proc macros vs builder method rationales. Discussion preceding this PR in payjoin#684 and [here](#1)
Refactors the code to use proc macros over the "legacy" builder method as per `clap`'s recommendation. The macros allow the code to be more maintainable, readable, and reusable moving forward. See [here](https://docs.rs/clap/latest/clap/_faq/index.html#when-should-i-use-the-builder-vs-derive-apis) for more details on proc macro vs builder method rationales. Discussion preceding this PR in #684 and [here](thebrandonlucas#1)
Refactors the code to use proc macros over the "legacy" builder method as per `clap`'s recommendation. The macros allow the code to be more maintainable, readable, and reusable moving forward. See [here](https://docs.rs/clap/latest/clap/_faq/index.html#when-should-i-use-the-builder-vs-derive-apis) for more details on proc macros vs builder method rationales. Discussion preceding this PR in payjoin#684 and [here](thebrandonlucas#1)
This WIP commit begins refactoring to use the derive macros provided by clap to replace the builder we are currently using. This is essentially a sample of how I intend to refactor this code if we are in agreement.
Clap appears to recommend using derive when a lot of flexibility isn't needed. See FAQ. I believe this would allow us to simplify the logic, make the code DRYer, make the code more readable and maintainable, and conform to
claprecommendations.There may barrier or complexity I'm failing to see here, but it seems like this refactor would make things much more maintainable and easier to build on moving forward. Also, if we find ourselves needing the lower-level API's provided by the builder method, we can still use it on an as-needed basis