Skip to content
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

Documentation ergonomics for enums: #146

Open
ysndr opened this issue Dec 19, 2022 · 3 comments
Open

Documentation ergonomics for enums: #146

ysndr opened this issue Dec 19, 2022 · 3 comments

Comments

@ysndr
Copy link
Contributor

ysndr commented Dec 19, 2022

When defining tuple enum variants the bpaf configuration (and doc comment) have to be set inside the tuple, on the tuple values.
For single value tuples that's annoying and brakes consistency with zero arg variants
I see how this is necessary with multiple tuple values but single valued tuples could be special cased to forward doc and bpaf config to the inner field for ergonomics.
This would also allow to infer the name of the flag.

#[derive(Bpaf, Clone, Debug)]
enum Verbosity {
    Verbose (
        /// Verbose mode.
        ///
        /// Invoke multiple times for increasing detail.
        #[bpaf(short('v'), long("verbose"), switch, many, map(vec_len))]
        usize,
    ),
	
    /// Quiet mode
    #[bpaf(short, long, default)]
    Quiet,
}
on batteries: I am aware of the verbosity flags contained in the batteries feature, this is just for demonstration
@pacak
Copy link
Owner

pacak commented Dec 19, 2022

So you want to be able to write something like this instead?

#[derive(Bpaf, Clone, Debug)]
enum Verbosity {
    /// Verbose mode.
    ///
    /// Invoke multiple times for increasing detail.
    #[bpaf(short, long, switch, many, map(vec_len))]
    Verbose (usize),
	
    /// Quiet mode
    #[bpaf(short, long, default)]
    Quiet,
}

I'll see what it takes to implement.

@ysndr
Copy link
Contributor Author

ysndr commented Dec 19, 2022

Yes.
I see that it is necessary for multiple fields or record variants, but for single ones some kind of surgar would be nice.

@pacak
Copy link
Owner

pacak commented Dec 22, 2022

Implemented this for enums, seems to work. Looking into doing the same for structs, this needs a bit more thinking... Will get back to this later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants