-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: Builder macro to assist with App/Arg/Group/SubCommand building #238
Conversation
I am the last fan of macros, but it looks very cool to me! Thank you! |
Due to the dynamics of the macro literally translating to the builder. The example is in itself, a test case. Compilation is the only thing that can really be tested. Past that, any tests are actually testing the builder itself - not the macro. @Vinatorul "I am the last fan of macros" did you mean you are "now a fan of macros", don't like, or don't yet understand them ? ;-) |
Additional note: The Any other possible tests would be implementation stress tests. I.e. An app with 64 arguments will not compile. However crazy, such SHOULD be broken down into subcommands at that point and the consumer should repeat over their list of subcommands - which if still more than 64 subcommands... They can always implement a macro like this one and then it's only limited to the AST token tree of rustc) Alternatively the consumer may also just go with the cheats way out with |
Yes it tests that macro builds but it can't claim that in works.
I meant |
@Vinatorul I'm not against a test case, but now we're limited to the input that is given to the macro. The complex example covers all features of the macro and I've manually verified the generated code. Bad input to the macro will generate bad code. This will cause a compile time error.
|
Only testcases that come to mind is to use the macro to generate an |
@james-darkfox This test can save once live when developer made copy-paste or misspell error, for example:
|
You successfully got me re-checking my code and generated code. =D Again... Such suitable test would need to be an equality test against two instances of |
Maybe I don't understand something, but why can't it be like this one, but with checks: https://github.com/kbknapp/clap-rs/blob/master/tests/yaml.rs |
I have a feeling that test gets optimized out to nothing anyway... Just typechecks. Nothing is stopping a test from existing. My original point was simply, that the example code stresses all features of the macro; and has been manually verified to generate the correct code. To programmatically confirm the integrity of the generated builder, is to simply check equality against a manually built and equivalent instance of |
Yes, example code stresses all features of the macro. Travis build finally ended, so let's wait for @kbknapp approvement. |
Future regression is indeed very important. I'm unsure without diving back into the code, if |
Also. As an extract from the checklist on #217
Sidenote, I feel that |
Looks great, I'm excited for this merge! @james-darkfox could you add a commit adding yourself to the
Yes, and no. "Yes" in that they typically don't. "No" in that they can have authors and settings and such (think third party The settings piece is a little more subtle. While normally it doesn't matter, there can be times when it's nice to give a subcommand the ability to have different settings from the parent commands or application in general (such as the need for mandatory args or further subcommands). |
@james-darkfox not sure which timezone you're in, so I'll give you a bit to put in the contributors commit. After a few hours, if nothing myself or @Vinatorul will merge and we'll just add your name in the next PR to update the versions and readme 😉 |
As for that subcommand search; no I haven't noticed such delay. I also think that should be settings gated as the consumer would opt for this if they wanted such subcommands from third parties. My timezone is AEST:Eastern Australia |
Perhaps, but nothing is lost leaving those settings un-gated except maybe compile time and polluting of API space? As for the API space, I'd actually prefer leaving it un-gated so all possible options are displayed in the docs without confusing consumers. I would say those settings are there if they need they want them, but aren't by any means required. If there is a detriment to leaving them un-gated I'm open for suggestions :) As for this PR, I'm happy to say Merged! |
feat: Builder macro to assist with App/Arg/Group/SubCommand building
Add missing fragment specifier to a clap_app! rule. Introduced in #238, this bug affects both `clap` `1.*` and `2.*` and was found by rust-lang/rust#39419. I'd suggest releasing not only `2.20.5`, but also `1.5.6`, to cover downstream crates still on `1.5.5`.
#217