Conversation
3a505bc to
2dff3c5
Compare
|
About the clap defaults, I think it might be possible to keep using them if we use But if all this works (and I don't know if it will, it's all just a theory from reading docs), then the Idk how much work this would be, but it would be really nice to keep using the clap default system. |
|
@katrinafyi Oh wow, thank you so much for the suggestion. I really missed that, or rather never consulted the docs properly enough 😅 I will definitely explore this path, thank you for pointing it out. |
20cea4d to
4d4fc89
Compare
|
So I've updated this PR with 4d4fc89. We can now specify Clap defaultsClap defaults are removed in the current state of the PR. This is because leaving them leads to incorrect behaviour. We want clap arguments to take precedence over config values, otherwise UX is quite confusing IMO. It would be much easier if this wasn't the case, but I think it really is unexpected to have CLI flags which are overwritten by values in config files. graph LR;
Config-A-->Config-B;
Config-B-->Clap;
There can be any amount of configs, this is just an example with two configs. If we decided to leave the clap default values, then if I've experimented with macros in thomas-zahner@605fe31 where I try to auto generate the "getter" methods and assert that the right default value is mentioned in the comment. But unfortunately it's not possible to evaluate const expressions in macros so that it's impossible to assert the default value is contained in the comment when it is a const literal. Also this seems to be quite overkill. Then I've tried your approach @katrinafyi in thomas-zahner@dbd36ce#diff-6168b1b6485695baf19bdea9ca3993b2c1f705821ab33f53775ad279ce2f6badR146. But this does not seem to work well. I see I'm open for ideas. Currently, I feel like the state of this PR is pretty much the most realistic version. Ideally I will write some additional tests, which might be able to assert that manually typed out default values (e.g. |
4d4fc89 to
9772dd8
Compare
|
@thomas-zahner with value source, was it particular flags which caused that problem? I was just testing it and it seems to work. I don't know what causes None vs Some(DefaultValue), but Some(CommandLine) does seem to be returned correctly as far as I can tell. But maybe I'm just rewalking the path you already tried. The API could definitely be safer and less stringy.. |
9772dd8 to
7367cb4
Compare
|
@katrinafyi Hmm, it basically worked for not a single argument in my test. See https://github.com/thomas-zahner/lychee/tree/clap-value-source-v2 Could you share your code if you got it working? |
|
Coincidentally, I just discovered the same issue 😆 It's really confusing. My code is at https://github.com/lycheeverse/lychee/compare/master..rina-forks:lychee:value-source. It does the merging by lowering to TOML and then it can use the TOML map to represent presence/absence. But it's a real headache with all the string keys and untyped toml AST. I think your approach is probably the least bad. Even if edit: or maybe the macro is ok. the hard part is just defining |
Oh wow, that looks like you put quite some work into it. But it also seems really complicated 😅 I've just come up with three tests in 3303cc0. What do you think? It seems much simpler and pragmatic to go with such conventions. And now as we test them it shouldn't be a problem. It also has the benefit that we show even more default values to the user. (e.g. as with archive) |
Yeah... I was following different threads at the same time so could be a little bit simpler, but it's definitely more complicated than I wanted or expected. It's just... I really don't like all the getters to apply the defaults - it's just so Java 😭 But it's something we'll have to deal with. Anyway, the tests you wrote look good and make sense. Let me know when it's ready and you want me to look through, I had some small comments queued. I might or might not rebase my changes after your PR is merged to see what it's like. Or maybe not if it's too much work, we'll see.. |
3303cc0 to
c154f2e
Compare
Haha yeah, I see your point. But at the same time I think it's an overall improvement, as we document more default values (accept & archive) than before and any mistakes should be prevented through the new tests. Also it's really low complexity, no macro magic. Overall the approach is pretty good now in my opinion. If you look at other bigger CLI applications you will see funny things, how they implement CLI parsing fully on their own without any library (ripgrep which switched from clap to their own implementation) or how they have duplicated structs one for CLI args and one for the config file. (fd) The PR is now ready for review. |
katrinafyi
left a comment
There was a problem hiding this comment.
It's good. verbatim_doc_comment is good actually because the old strings had weird indentation. Also, adding more merge functions to structs is a good idea. It's also good to delete the more odd macros like default_function!.
Unfortunately, there's a bug but, aside from that issue, the comments are small.
d587e80 to
5d01ba7
Compare
In case the default config fails to load, the error message is still very clear.
In return, remove the overly specialised --secrets flag.
Co-authored-by: katrinafyi <39479354+katrinafyi@users.noreply.github.com>
5d01ba7 to
a20be99
Compare
Use HashMap instead of Vec Remove parse_default_options Special handling of user_agent
katrinafyi
left a comment
There was a problem hiding this comment.
looks good., just one more code suggestion down there 👇
also, idk if you planned to do this while merging, but if you change the title to start with "feat:", it gets shown in the Added section of the next release notes. it's fun to call out exciting new features
Co-authored-by: katrinafyi <39479354+katrinafyi@users.noreply.github.com>
9f0da94 to
4161a2f
Compare
|
@katrinafyi Thank you for the thorough review! |
|
A really small thing but were these two comments meant to make it in #2007 (comment) #2007 (comment)? Or did you choose to leave them out? |
|
@katrinafyi Oh, that's what happens when you apply all review suggestions and then address the test failures by copying the diff blindly from the test output 😄 (I assumed there were no suggestions in the README) See 5500879 |
|
Aha I see, that's so fair. I should put the suggestions in the rust side next time :)) |
Allow specifying an additional config files for managing secrets by manually implementing
Configmerging.Fixes #1298
Fixes #1959
Fixes #1952
Questions
@mre The only problem I see with this PR right now is that we loose the benefit of clap default which is the automatically appended text to the help message & man pages which I've now appended manually to the comments. Ideally we'd do some macro magic so that we don't have to manually add these defaults in such an error prone way, or alternatively have a test which verifies that
[default: X]matches the actual values ofConfig::default().my_option(). But both ideas aren't easy to implement. Do you see any alternatives or do you think merging it in the current state is fine?