Skip to content
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

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

Open
dievilz opened this issue Mar 14, 2024 · 7 comments
Open

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

dievilz opened this issue Mar 14, 2024 · 7 comments

Comments

@dievilz
Copy link

dievilz commented Mar 14, 2024

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
Copy link
Owner

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
Copy link
Author

dievilz commented Mar 14, 2024

Sure, thanks for the quick response.

I have this command: $(docker ps -aq --no-trunc --filter name=^/"<name_of_the_container>")
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
Copy link
Author

dievilz commented Mar 14, 2024

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

@shenwei356
Copy link
Owner

Not supported, but there's a workaround solution.

docker images -f dangling=true -q | rush 'docker rmi || true'

@dievilz
Copy link
Author

dievilz commented Mar 14, 2024

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
Copy link
Owner

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
Copy link
Author

dievilz commented Mar 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants