zummenix opened PR #1335 from clif-util-stdin
to master
:
This enables
clif-util run -
to work with stdin (seems it was intended initially).Now errors in
iterate_files
are propagated further.Closes #1004
abrown submitted PR Review.
abrown created PR Review Comment:
I was a bit confused reading this but tell me if I understand this correctly: if we pass
"-"
insidefiles
thenWalkDir
will give us an error; however, we _can_ turn"-"
into a validPathBuf
by doinge.path().into()
?
zummenix submitted PR Review.
zummenix created PR Review Comment:
Yes, that's correct. We propagate all paths that
WalkDir
wasn't able to deal with toread_single_file
function. I agree this is a bit clever and confusing but I wasn't able to find a better way.
abrown submitted PR Review.
abrown created PR Review Comment:
What about the following approach: why don't we separate out any strings that we know to have special semantics and chain them on the end of the iterated files? E.g.:
let (normal_files, special_files) = drain_specials(files); for file in iterate_files(normal_files).chain(special_files)Where
drain_specials
could be something like (there's surely a better way):/// This could use `drain_filter` instead but it is a nightly-only experimental API. fn drain_specials(mut files: Vec<String>) -> (Vec<String>, Vec<String>) { let mut normals = vec![]; let mut specials = vec![]; for s in files.drain(..) { match s.as_str() { "-" => specials.push(s), _ => normals.push(s), } } (normals, specials) }The reason I propose something like this is to avoid the catch-and-then-use of
e.path().into()
which feels hard to debug (and to read too, as you mention).
abrown edited PR Review Comment.
zummenix created PR Review Comment:
Does it make sense to have multiple stdin inputs? For example with
clif-util run - -
user fills in first input and then second. If not, then we can check if stdin arg exist, filter out all the-
fromfiles
andchain
the-
at the end as you have proposed.
zummenix submitted PR Review.
abrown submitted PR Review.
abrown created PR Review Comment:
Yeah, to me deduplicating special things like
-
makes sense.
zummenix updated PR #1335 from clif-util-stdin
to master
:
This enables
clif-util run -
to work with stdin (seems it was intended initially).Now errors in
iterate_files
are propagated further.Closes #1004
abrown submitted PR Review.
abrown merged PR #1335.
Last updated: Nov 22 2024 at 17:03 UTC