-
Notifications
You must be signed in to change notification settings - Fork 17
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
Derive attribute to make command enum #178
Comments
Sorry about that, I'm trying to improve the docs as I can, I guess I should go over the derive tutorial as well if people are using it as an entry point to derive API. Either way - naming used by derive macro should match names used by combinatoric API. As for the proposal - am I correct that this is a way to avoid typing pub enum MyCommand {
/// List your accounts
#[bpaf(command("list")))]
Accounts, |
No worries, I'm already glad it's even there, that's good work. In a matter of feedback, which gets me the most is trying to put a parser inside other parsers. For example i tried using #[derive(Debug, Clone, Bpaf)]
pub enum MyCommand {
/// Logout of a account
#[bpaf(command)]
Logout(
/* should i put documentation here? */ #[bpaf(external(no_save))] NoSave,
),
}
/* or maybe here? */
#[derive(Debug, Clone, Bpaf)]
pub struct NoSave {
/* or here instead? */ no_save: bool,
}
// i can't manage to compile this
// even if it's just an positional argument
#[derive(Debug, Clone, Bpaf)]
pub struct NoSave(bool); This is so bad, i actually abuse
About the naming, i mean things like
Yes. If you want to do this type of enum, you have to make pretty sure you aren't forgetting a variant without
Then could we use them optionally? something like this: #[derive(Debug, Clone, Bpaf)]
#[bpaf(command_enum)]
pub enum MyCommand {
/// List your accounts
#[bpaf(command("list")))]
Accounts,
/// Login into a account
Login,
/// Logout of a account
Logout {
no_save: bool
},
/// Change status
Status,
/// Force save current state
#[bpaf(command("exit")))]
Save,
} We can use other attribute than Also, this // generates a `my_command() -> impl Parser<MyCommand>`
#[derive(Debug, Clone, Bpaf)]
#[bpaf(command_enum)]
pub enum MyCommand {}
// generates a `my_command() -> ParseCommand<MyCommand>`
#[derive(Debug, Clone, Bpaf)]
#[bpaf(command_enum, command)]
pub enum MyCommand {}
// generates a `my_command() -> OptionParser<MyCommand>`
#[derive(Debug, Clone, Bpaf)]
#[bpaf(command_enum, options)]
pub enum MyCommand {} I'm sorry if it's too hard to implement, i don't actually know how it's done yet. |
documentation goes to
This is somewhat intentional, I guess I'll improve improve the error message. Having positional #[derive(Debug, Clone, Bpaf)]
pub struct NoSave(#[bpaf(positional)] bool);
would be great if you show me any specific issues you had, at the moment documentation contains this:
followed by an example.
Hmm... The idea was to have
I see, I need to think on that a bit more, it doesn't fit very well Made this for now: #179 |
It seems like But sorry, i was mistaken about the Overall, I think it boils down to just have more common practical examples in the documentation. In the section 5 of the docs, it explains "consumer section corresponds to argument, positional, flag, switch and any." but there's only a example using
#[derive(Debug, Clone, Bpaf)]
struct Path(#[bpaf(positional("PATH"))] PathBuf);
#[derive(Debug, Clone, Bpaf)]
struct Path(#[doc = "path used in the program"] PathBuf);
I'm curious, why did you named it like this? I mean, it could be like |
It's fixed in
I see. Documentation might not be directly in the tutorial section, but pretty much every function comes with examples with both APIs and how it interacts with real command line inputs - they are generated and tested, see this for example, try clicking at lines marked with triangle: https://docs.rs/bpaf/latest/bpaf/trait.Parser.html#method.map It also lists 12 different fully implemented parsers from
Mostly historical |
Wow, i didn't notice how rich the docs.rs normal documentation was; the tutorial don't come even close! |
I searched a way to do this but i couldn't. I may have missed it, since the derive docs and naming are very confusing, at least for me.
What i want is a macro attribute (e.g.
command_enum
) as the other Generated function types that makes the following conversion:Right now (version 0.7.2)
Proposed
The text was updated successfully, but these errors were encountered: