-
-
Notifications
You must be signed in to change notification settings - Fork 783
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
Multi exec #960
Multi exec #960
Conversation
Oh - very cool! Thank you for working on this. Let us know when it's ready for review. |
One issue here is if you run something like:
then you can end up printing baches of directories then batches of basenames instead of writing the directory and base name together, because the commands are run in parallel. There are a few things we can do about this:
I'm leaning towards 3 or 4, what are your thoughts? |
My latest commit implements 4. All that remains is writing some tests. |
Biggest downsides to using 3 or 4 are that it can result in higher memory usage, and potentially delay output from the first exec command(s). There will also be slightly higher overhead for allocating the buffers. That could probably be mitigated somewhat by using a |
ae98814
to
2427b1f
Compare
I think 4 makes sense since we already buffer anyway, might as well buffer everything for each file. Maybe we should implement a limit to the buffering? Right now |
Thank you, I'm planning to take a look soon. |
and `--exec-batch`. Fixes: sharkdp#406
So that if multiple `--exec` options are given, and the commands are run in parallel, the buffered output for related commands will be consecutive.
I found the following problematic case:
(maybe we could improve the error messages here) Using
If |
Benchmarks look good (no change when running a single command) 👍 Command execution
Command execution (large output)
|
// TODO test for windows | ||
if cfg!(windows) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the problem here? Only the path separator (/
vs \
)? I think we have code somewhere to replace them automatically?
echo
should be available on Windows as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think echo
is only a shell builtin on Windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests seem to indicate otherwise, right?
Lines 1480 to 1501 in 0fd7ec5
/// Shell script execution (--exec) with a custom --path-separator | |
#[test] | |
fn test_exec_with_separator() { | |
let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES); | |
te.assert_output( | |
&[ | |
"--path-separator=#", | |
"--absolute-path", | |
"foo", | |
"--exec", | |
"echo", | |
], | |
&format!( | |
"{abs_path}#a.foo | |
{abs_path}#one#b.foo | |
{abs_path}#one#two#C.Foo2 | |
{abs_path}#one#two#c.foo | |
{abs_path}#one#two#three#d.foo | |
{abs_path}#one#two#three#directory_foo", | |
abs_path = abs_path.replace(std::path::MAIN_SEPARATOR, "#"), | |
), | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that test fails on my Windows VM. I bet GIt Bash or MSYS or something installs an echo.exe
binary that gets picked up on CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just following what we did in the test_exec and test_exec_batch, and (specificaly) test_exec_batch_with_limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'm fine with skipping Windows for now.
In this case, the only open point I see right now is the problem mentioned above (#960 (comment)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you already reported it upstream. Thanks!
Accepting multiple occurances means we need to check this ourselves. See clap-rs/clap#3542.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
One thing that I would like to discuss (independent from this PR) is the syntax for passing multiple commands. This might be a personal thing, but I really dislike the ;
syntax for "ending" the list of arguments. It is ugly, needs escaping, and is hard to type (on German keyboards). It's also potentially confusing since ;
has special meaning in a shell so users really need to understand the escaping part here.
fd … -x echo \; -x do_something
Is there any way we can provide something easier here? Using ;
for separation has precedent in find
, of course, but it's not like that's something universal. It's just a convention.
One option would be to come up with a different value terminator character or sequence (https://docs.rs/clap/latest/clap/struct.Arg.html#method.value_terminator). --
would be one common option, but that has special meaning already. So this would likely not work(?). But let's say we use something that's easier to type and doesn't need escaping:
fd … -x echo :: -x do_something
This would only cause problems if someone actually wants to pass ::
to a command. But the same is true for the semicolon.
Another idea might be to provide a way to get rid of both: the value separator and the additional -x
/--exec
option. For example, we could choose a special character sequence (let's say +
or ++
) to directly combine two commands:
fd … -x echo + do_something
What do you think?
personally I prefer the I do like the idea of having a delimiter so you don't have to specify What do you think of keeping |
I agree. Let's keep |
No description provided.