bpaf icon indicating copy to clipboard operation
bpaf copied to clipboard

Documentation ergonomics for enums:

Open ysndr opened this issue 3 years ago • 3 comments

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

ysndr avatar Dec 19 '22 13:12 ysndr

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.

pacak avatar Dec 19 '22 15:12 pacak

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

ysndr avatar Dec 19 '22 18:12 ysndr

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.

pacak avatar Dec 22 '22 18:12 pacak