-
-
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
Feature: Custom Derive for ArgEnum #1659
Comments
Hey! cc @TeXitoi Excellent! This is a great start towards my ideas for 3.x. I've cc'd @TeXitoi because I'd like to re-invigorate the move towards 3.x and finishing the CustomDerive piece is a big part of that movement. With my job monopolizing my time this kind of fell off in #835 but now that the v3-master branch is coming together it's worth working towards again. The grand plan is to create a
I was tentatively planning on storing all the If both @Hoverbear and @TeXitoi think the design is sound/doable I'd like to make PRs against the v3-master branch, or if keeping individual repos is better, making PRs against the |
Here are the unknowns still, and what needs to be decided Supporting Subcommands via CustomDeriveWe need to find out how to support a struct with arbitrary options/flags and also a subcommand, and how that gets represented via CustomDerive. I believe @TeXitoi suggested an enum, where each variant holds it's arbitrary struct representation. I'm good with this, and we just need to work towards ironing out the details and actually implementing. I believe this would also require adding another The hard part is how does this work ergonomically. Some code examples. I want the end user result to be as close as possible to to this: #[derive(ClapApp)]
struct MyApp {
flag: bool,
subcommand: MySubCommand
}
#[derive(ClapSubCommand)]
enum MySubCommand {
Foo(FooCommand),
Bar(BarCommand),
}
#[derive(ClapApp)]
struct FooCommand {
verbose: bool
}
#[derive(ClapApp)]
struct BarCommand {
name: String
}
fn main() {
// run with `$ myapp bar kevin`
let app = MyApp::parse();
match app.subcommand {
FooCommand(foo) => println!("Verbose used?: {:?}", foo.verbose),
BarCommand(bar) => println!("Hello {}!", bar.name),
_ => println!("No subcommand used."),
}
} Supporting ASCII Case Insensitive ArgEnumsAs @Hoverbear and I discussed briefly at RustBeltRust, we need these ArgEnums to be case insensitive, but I'd also like an opt-in version that is case sensitive (perhaps via a different Supporting Hyphens
|
From @Hoverbear on November 12, 2017 19:28 @kbknapp Please be aware custom derive crates must only contain custom derives. So we'd need a |
From @Hoverbear on November 12, 2017 19:29 For case sensitivity around |
From @Hoverbear on November 12, 2017 19:33 @kbknapp You should have a transfer request in your inbox. |
Ah ok I wasn't aware of this having not done much with CustomDerive. OK separate repos it is, I'm good with it 😄 👍 |
clap-rs/clap_derive#4 doesn't specify this much. Is there any remaining feature this should handle? I think expanding the examples would be a good idea as well.
|
Just to comment about 2 repos: derive crates need to be separate, but you can put several crates in a repo. And such a repo will not be independent from the rest, we need a normal crate to define the traits that will be implemented by the derive crate. (maybe not for ArgEnum as it implement |
About structopt, it is feature-full for me since about a week thanks to external contributors. It now support subcommands, calling any I will not have time to contribute by porting structopt here, but I'm available to review everything about that and giving my opinion. @kbknapp if you can check the current status of structopt. I'm very interested by your feedbacks about the interface. If you like or dislike some syntax, and if you see any critical lacking feature. Note that I don't think having 2 derives for Maybe we can open issues to talk about all that. |
@TeXitoi no worries, I'm low on time over the next few weeks as well due to holidays and travel. I'll gladly take a look once I get some time 😄 I'll do some porting too once I get a little extra time. So that it's clear too, I intend to use as much code from structopt as possible without many changes unless I happen to see something that is directly contradictory to how clap does it...which doubt I'll find 😜 I'd also like to maintain all commit history so that @TeXitoi doesn't lose any commits. (Just FYI in case someone else starts doing some porting, I don't want to simply copy-paste and erase all commit history 😉) |
@kbknapp Maybe we could merge this repo into that one instead of the other way around? |
@CreepySkeleton This is possibly related to multiple traits. |
Yeah, kind of, but it can wait until beta. The nearest milestone is alpha, just to show people the project is still alive / being resurrected. I'm getting custom derives to work, anticipated time is ~5 hours from now (I'll get to it in ~3 hours since I have some urgent stuff to do now, sorry for delay). Then we can get rid of |
Some implementation is at clap-rs/clap_derive#15 |
From @Hoverbear on November 12, 2017 18:11
Hey!
I had a bit of time, and a hankering to write a custom derive, so I got working on a custom derive for
ArgEnum
.I've structured the crate so if we want to expand it, it should be easy. I think this is related to #835 but I didn't look too deeply into what the progress is with that.
The crate is https://github.com/Hoverbear/clap-derives and unpublished, and I'd be more than happy to transfer you (@kbknapp) ownership. It's a first draft and could probably use refinement.
You can see an example here:
Will derive this:
Copied from original issue: #1103
The text was updated successfully, but these errors were encountered: