clap derive: trouble using BTreeSet<OsString> instead of Vec<OsString> #5437
-
I have a working clap derive struct which looks like this: /// List directories of files, show single line summary of chunks
#[derive(Parser, Debug)]
#[command(long_about = None)]
struct ListConfig {
/// directory to list
#[arg(default_value = ".")]
path: OsString,
/// Filter to only these extensions, case insensitive.
///
/// To include multiple extenstions, specify the option multiple times:
/// Ex: --ext=wav --ext=wave
#[arg(long, short, default_value_os = "wav")]
ext: Vec<OsString>,
/// Recurse through subdirectories as well
#[arg(long, short, default_value_t = false)]
recurse: bool,
} For correctness, the list extensions should be a set. If I try to change the
I get an error:
... and I have to admit that I've both failed to understand the root issue and where to start fixing it. ValueEnum seems like it's for Enums, ValueParserFactory seems like it's just to register with the value_parser macro. From the rest of the traits, it seems like maybe I need to wrap BTreeSet and implement converstions from strings? But that seems more like parsing one argument, rather than inserting into the set. Probably I'm just looking in the wrong place. :) If anyone has advice on where to start, I'd greatly appreciate it. In particular, I'd love to see a reference for how it's implemented for Vec, so I could do something similar for BTreeSet. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
At this time, we don't support arbitrary collections. We are tracking this in #3114. Of particular interest for a As for the error, it is because it is seeing the |
Beta Was this translation helpful? Give feedback.
At this time, we don't support arbitrary collections. We are tracking this in #3114. Of particular interest for a
Set
is whether redundant values should be an error or ignored.As for the error, it is because it is seeing the
BTreeSet
and is thinking that you are trying to parse a single value into that but doesn't know hiw.