-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Would like path_of #1723
Comments
I'm not very excited about adding yet another output format, but we can make it if paths are really so common, perhaps under
That's definitely up to user. Even |
CLI tools of course have filenames as a common use case.
Well, I was just speculating, but naturally if the user doesn't want it validated, they could just use |
Except, what does "valid path" means? |
On Windows, a Path may not contain On Linux, I think there are no restrictions other than of course the null termination. |
This kind of checking would be largely useless. The os facilities would check it anyway ( Come to think about it, |
It would be only me, I'd say no. I'm not really convinced by the added feature. |
It is definitely trivial. I would consider this one of those things where if more people request it, I wouldn't mind adding it. |
@pksunkara Which one? The checking or the conversion? |
Conversion |
Another compelling argument in favor is that I believe it's more teachable: If a user has an &str, they can pass it directly into |
Good try, but it can 😮 |
Doh. Yes because File accepts |
Well, the argument was about flattening the learning curve, wasn't it? I've swept through I see your point about |
Closing as inactive. I don't think this feature is of any use, and, evidently, almost nobody wants it. |
Please don't close any issues just because nobody commented they needed it. There could always be a future feature request. |
I believe #2683 should supersede this, closing it. |
Use case
It's common to get a filename from clap with
value_of_os
and its companionvalues_of_os
. You often want to turn it into aPath
in order to pass it tostd::fs::File::open()
.The only way I've been able to find to turn an
OsStr
into aPath
is withPath::new()
, which is a bit wordy. Therefor, it'd be nice be able to get Path objects directly.Proposed solution
It'd be nice if there were a function like
Matches::path_of(name: &str) -> Option<&Path>
so that you can get aPath
in a single function call.Alternate names for
path_of
might be the consistent but less concisevalue_of_path
but that somehow reads grammatically different thanvalue_of_os
, not to mention being longer. Therefor,path_of
sounds better.Additionally, you'd want
paths_of
the way there isvalues_of_os
Hypothetically, one could also make it reject (at
get_matches
-time) impossiblePath
s (on Windows, not all Paths are valid).Alternative solutions
The standard library could get some sort of convenient shorthand for turning
OsStr
intoPath
. I think adding the function intoclap
serves the purpose better because it self-documents better while keeping std clean and explicit.The text was updated successfully, but these errors were encountered: