How to have an multi-valued option with auto generated help? #197
-
I want something like this in the help message:
Where I have the following code: enum Style {
A,
B,
C,
}
impl FromStr for Style {
// ...
}
#[derive(Debug, Clone, Bpaf)]
#[bpaf(options, version)]
struct Args {
// ...
/// Style of template
#[bpaf(short, long, fallback(Style::A))]
template: Style,
// ...
} This clearly doesn't work as is, (the Bpaf macro cannot inspect Style for what styles are supported), I couldn't get any version of this working. I tried adding the Bpaf macro to Style as well and using I would also like support for completion for this Style enum. Again a custom one could be coded by hand. Thus my question is: Is there an elegant/automatic way of doing it that I'm missing? Or should I do the complicated hand written one (where I have to keep multiple different lists of things in sync)? And should I file a feature request? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
It should be possible to implement as combinatoric function similar to here. You define a parser for template field something like this: fn template() -> impl Parser<Style> {
let help_msg = format!("....."); // <- you can use `strum` to get exact names and put it in the help message in a way you like
// again, with help of strum you can get a list of values and decide if it maches
fn complete_fn(input: &String) -> Vec<...> {}
// name
short('t').long("template")
.help(help_msg) // help mesage generated by strum
.argument::<String>("ARG") // consume it as string because completion will need a string to work with
.complete(complete_fn) // try to complete with help of strum
.parse(|x| x.parse()) // use `FromStr` to parse it to `Style`
} Then use it in your parser via I can try to make a working example if it's still unclear. |
Beta Was this translation helpful? Give feedback.
-
Took a bit longer but changes to generate better help are in master branch, will release soon-ish after going over documentation. |
Beta Was this translation helpful? Give feedback.
It should be possible to implement as combinatoric function similar to here.
You define a parser for template field something like this: