-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
derive: default to parse_os_str for OsString or PathBuf types #3496
Comments
Huh, I know I had considered this at one point but I can't find an issue for it. I do wonder / hope for #2683 to help with this class of problem in the long term. I know one odd thing is for us to define how we detect these types since we just get the textual name (iirc). For example, for external subcommands, we only support As for when to do this, an awkward thing is we haven't fully defined what our compatibility story is because users might set attributes assuming what attributes we set or make direct calls on a generated |
@epage One approach that might be viable on a clap 4 timeframe would be to do all conversions by way of bytes, and then conversions to String can check for UTF-8, while conversions to OsString or PathBuf or similar wouldn't. (On a comparable timeframe, we might manage to make OsString's use of bytes transparent in the standard library.) I'm also hoping such a change would make it easy to handle Meanwhile, in the short term, it seems vaguely reasonable to have the automatic behavior work the same way you're currently handling |
Just realized, changing any of this in the short term might be considered a breaking change since we would be implicitly setting Something we've not fully defined is our expectations for the derive: how much can people expect from the behavior of the derive when they do not use it in a self-contained way (pairing the generated |
For clap 3, its opt-in as a precaution against breaking compatibility in some weird cases. This does require the types to implement `Clone`. Fixes clap-rs#3734 Fixes clap-rs#3496 Fixes clap-rs#3589
Please complete the following tasks
Clap Version
3.1.1
Describe your use case
Most CLI applications should handle any path the user provides, not just UTF-8 paths. I'd like to make that easier to do by default when using
derive
, without having to remember to change the parse function.Describe the solution you'd like
Currently, according to the documentation, parsing non-UTF-8 paths requires using
parse(from_os_str)
.I'd love to see this become the default if deriving an argument with a field type of
PathBuf
orOsString
, to automatically do the right thing with paths.Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: