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

arg_enum! case insensitivity doesn't work with possible_values #891

Closed
LegNeato opened this issue Mar 7, 2017 · 2 comments
Closed

arg_enum! case insensitivity doesn't work with possible_values #891

LegNeato opened this issue Mar 7, 2017 · 2 comments

Comments

@LegNeato
Copy link
Contributor

LegNeato commented Mar 7, 2017

Enum case insensitivity was add in #104.

Unfortunetly, if you use possible_values() with your enum (for example, possible_values(&MyEnum::variants())) case insensitivity is lost.

This means the helpful clap error message listing supported values cannot be used and one must handle it manually.

Rust Version

rustc 1.15.1 (021bd294c 2017-02-08)

Affected Version of clap

clap 2.20.3

Expected Behavior Summary

Because the enums are case-insensitive, I expected possible_values to be case insensitive as well.

Actual Behavior Summary

Using possible_values makes enums act like they are case-sensitive again.

Steps to Reproduce the issue

  1. Create an enum using arg_enum!
  2. Make sure a variant has a capital letter
  3. Create an arg, set possible_values to the enum
  4. See that clap treats foo and Foo input values differently
@kbknapp
Copy link
Member

kbknapp commented Mar 10, 2017

Unfortunately, using possible_values has always been case sensitive. This is partly by design though, as there may exist cases where people wish to support different values which differ only in capitalization. Assuming you only want to support lowercase variants (which is the most common case by far), you could use something like

&MyEnum::variants().iter()
                   .map(std::ascii::AsciiExt::to_ascii_lowercase)
                   .collect::<Vec<_>>()

@LegNeato
Copy link
Contributor Author

Ah, ok. It was a bit counter-intuitive to read the issues about adding case-insentivity to arg_enum but still seeing case-sensitive behavior.

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

No branches or pull requests

2 participants