Would like path_of #142
Comments
Comment by CreepySkeleton 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 |
Comment by njaard
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 |
Comment by CreepySkeleton Except, what does "valid path" means? |
Comment by njaard
On Windows, a Path may not contain On Linux, I think there are no restrictions other than of course the null termination. |
Comment by CreepySkeleton This kind of checking would be largely useless. The os facilities would check it anyway ( Come to think about it, |
Comment by TeXitoi It would be only me, I'd say no. I'm not really convinced by the added feature. |
Comment by pksunkara It is definitely trivial. I would consider this one of those things where if more people request it, I wouldn't mind adding it. |
Comment by CreepySkeleton @pksunkara Which one? The checking or the conversion? |
Comment by pksunkara Conversion |
Comment by njaard 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 |
Comment by CreepySkeleton
Good try, but it can 😮 |
Comment by njaard
Doh. Yes because File accepts |
Comment by CreepySkeleton
Well, the argument was about flattening the learning curve, wasn't it? I've swept through I see your point about |
Comment by CreepySkeleton Closing as inactive. I don't think this feature is of any use, and, evidently, almost nobody wants it. |
Comment by Dylan-DPC Please don't close any issues just because nobody commented they needed it. There could always be a future feature request. |
Issue by njaard
Wednesday Mar 04, 2020 at 23:47 GMT
Originally opened as clap-rs/clap#1723
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: