shenwei356 / rush

A cross-platform command-line tool for executing jobs in parallel
https://github.com/shenwei356/rush
MIT License
846 stars 63 forks source link

Equivalent argument of GNU xargs -r (--no-run-if-empty) #56

Open dievilz opened 3 months ago

dievilz commented 3 months ago

Hi! Pretty much the title. As the repository doesn't have a Discussions page, I'm asking here.

As I want to replace my utils with Go equivalents, I want to replace xargs with rush but I can't seem to find the equivalent option. -c for continue doesn't seem like it, besides the fact that it creates a file, which is something I don't want.

Thanks in advance!

shenwei356 commented 3 months ago

I don't understand it :(.

  -r, --no-run-if-empty        if there are no arguments, then do not run COMMAND;
                                 if this option is not given, COMMAND will be
                                 run at least once

Can you give some examples?

dievilz commented 3 months ago

Sure, thanks for the quick response.

I have this command: $(docker ps -aq --no-trunc --filter name=^/"") which searches for all current Docker containers and filters by name

I pipe it to xargs -r docker container rm and use it inside a CI/CD pipeline, so it can delete the specified containers.

With GNU xargs -r, if the specified container doesn't exist, then it does nothing and exits with an error code of 0, which is what I want.

But I can't seem to find the equivalent in rush, I don't even know if this feature exist, so I wanted to know.

dievilz commented 3 months ago

Another example could be: docker images -f dangling=true -q | xargs -r docker rmi

shenwei356 commented 3 months ago

Not supported, but there's a workaround solution.

docker images -f dangling=true -q | rush 'docker rmi || true'
dievilz commented 3 months ago

Oh well, never mind then.

Another question... Do you think this feature is out-of-scope for rush? If it can be added, I would be very glad to contribute to rush and make a PR if you like!

I'm not sure if this feature is widely used, but since it depends on a GNU extension, if it's implemented in this project simply and elegantly, it could be a step forward for rush to be used by users who rely on GNU xargs like me.

shenwei356 commented 3 months ago

Sure PR is welcome. To be honest, this project gets complex for me. Some low-level (process and signal) operations contributed by @bburgin are hard to understand for me :( So I might I may not be able to help.

Personally, I rarely use that feature.

dievilz commented 3 months ago

Alright, the idea would be to implement the feature as simple as possible, and if its not feasible that way, then I would just leave it as it is.