Modifying the clap's parsing of the struct name


I am trying to create a small command line interface for an API our lab works with a lot. I am using clap for parsing my command line arguments and its really helpful. However, I am noticing a behavior that I'd like to modify.

I have two arguments that are enums as they should only take certain specified inputs. When clap outputs the options it separates successive capital letters by a hyphen. I'd like to turn this off for certain ones.

Here's an example:

With the enum

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum ItemType {

I get the following output:

error: "ALL" isn't a valid value for '--item-type <ITEM_TYPE>'
	[possible values: all, uni-prot-id, protein-gene-name, pmid]

I'd like that split to not happen for UniProtId (i.e get uniprot-id rather than uni-prot-id). I could change capitalization in my enum but I would prefer to keep the source code directly mappable to the real world entities.

Which trait needs to be implemented to modify this behavior?

Would #[clap(name = "uniprot-id")] on the UniProtID variant work? (Documented here.)

1 Like

Thank you. That worked.

To people looking at it later (including myself), the attributes can be set at any time.