-
-
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
Tracking issue CustomDerive #1661
Comments
Absolutely, me too! If we can resolve those outstanding questions above (values in order, ensuring The subcommand enum not being inlined I'm fine with. I forgot to mention in the last post the example above merges two distinct ideas into one, but I'd also want the ability to do one or the other and not be forced to use both. I haven't dug into the source yet, so if it's already possible ignore this comment 😜 What I mean is, I view both of these as distinct ideas (also, I'm using
Being able to do these two things separatly would greatly increase adoptability. i.e. "I've already got an Likewise, if for some unknown reason they don't want to use the |
From @Nemo157 on January 30, 2017 7:24 😃 I would definitely be happy to make this a part of
At the moment, definitely not. I was basically using my application and the primary
Yeah, again because of the test cases I was using I did not consider that at all. Hopefully, at least for the case where the user both generates the
Depends which way you mean, an anonymous enum in the parent command would be cool, but probably not really doable without proper anonymous enum support in Rust. An enum with struct variants definitely should be possible, it would result in some massive generated code blocks, but that shouldn't be too bad, and could be fixed in the future with types for enum variants allowing delegating variant specific parsing.
The trait doesn't allow it, but the macro is basically following two distinct paths for each so would be simple to split the trait for it. Also, one thought I had soon after I implemented this was that the macro is doing too much. It should be possible to split a lot of what the macro is doing based on types (which is actually based on type names, so could very easily be broken with type aliases etc.) out to trait implementations. For example something like I think I should have some time this week I could spend on this, I can definitely try and do a quick port into the |
So the example would go to: /// Does awesome things.
#[derive(ClapApp)] // Does both IntoApp, and FromArgMatches
#[clap(name = "MyApp", version = "1.0")]
#[clap(author = "Nemo157 <[email protected]>")]
pub struct MyApp {
/// Sets a custom config file
#[clap(short = "c", value_name = "FILE")]
config: Option<String>,
/// Sets an optional output file
#[clap(index = "1")]
output: Option<String>,
/// Turn debugging information on
#[clap(counted, short = "d", long = "debug")]
debug_level: u64,
#[clap(subcommand)]
subcommand: Option<Commands>,
}
#[derive(SubCommands)]
pub enum Commands {
Test(Test),
}
/// does testing things
#[derive(ClapApp)]
pub struct Test {
/// lists test values
#[clap(short = "l")]
list: bool,
} |
@kbknapp Have you stopped work on this? The derive/struct approach is a game changer. I can see a substantial productivity boost from having to define a struct and clap deriving the required parsing for it. |
@omarabid yes Kevin has been busy. It doesn't mean he has stopped working on it, but there are other priority issues to tackle. If you are free, you can send us a PR implementing any one of the above features and we will be happy to review it. Thanks |
@Dylan-DPC I can't promise as I just started learning Rust. On the other hand, if I were to start contributing to OS projects it'll definitely be this. |
@omarabid no issues. we can help you if you are stuck on anything. |
@omarabid while waiting for clap_derive to be finished, you can use https://crates.io/crates/structopt |
@CreepySkeleton This is also related to custom traits. |
Yeah, essentially the same design I've been thinking about 👍 |
For the ArgEnum thing, you may also be interested by https://crates.io/crates/strum it lacks almost nothing to be just enough. |
Hey :) I'm just in the middle of trying the new Clap v3 derive setup. However while migrating, I stumbled upon a little problem. Everything worked perfectly fine until I tried to use the new derive system in combination with the new shell completion generation functions. My current approach is something like this:
So here's my questoin: There's probably just something I'm overlooking. Thanks in advance :) |
You don't need to specify IntoApp derive. Clap derive automatically does that. Just make sure that IntoApp trait is in |
I really like the derive stuff, it's great! /*
Available functions:
reqwest::Url::try_from(s: &'a str) -> Result<Self, Self::Error>
reqwest::Url::from_str(input: &str) -> Result<Url, crate::ParseError>
scraper::Selector::try_from(s: &'i str) -> Result<Self, Self::Error>
*/
#[derive(Clap, Debug)]
#[clap(name = env!("CARGO_PKG_NAME"))]
struct Args {
#[clap(
takes_value = true,
parse(try_from_str)
)]
url: Url,
#[clap(
takes_value = true,
parse(try_from_str),
)]
selector: Selector,
}
Parsing |
Can you please create a separate issue? |
We've got examples and tests but are still lacking in docs. I've split that out into #2856 If there is anything in this that I missed, let's split it out so we can have concrete steps to move forward. |
From @kbknapp on July 6, 2015 1:22
Comments have been cleaned up and updated. This thread should be related to general progress towards 1.0 for this crate.
To Do
#[derive(FromArgMatches)]
#[derive(IntoApp)]
#[derive(ClapApp)]
(Automatically does bothFromArgMatches
andIntoApp
)#[derive(ClapSubCommands)]
#[derive(ArgEnum)]
Reference
Derive FromArgMatches
Derive IntoApp
Derive Subcommands
Derive TryFromArgMatches
Derive ArgEnum
Copied from original issue: #146
The text was updated successfully, but these errors were encountered: