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

--files-without-match reports an error when used with a single file path #1106

Closed
ShadowIce opened this issue Nov 14, 2018 · 3 comments
Closed
Labels
bug A bug.

Comments

@ShadowIce
Copy link

What version of ripgrep are you using?

ripgrep 0.10.0
-SIMD -AVX (compiled)

How did you install ripgrep?

cargo install ripgrep

What operating system are you using ripgrep on?

Windows 10

Describe your question, feature request, or bug.

I'm trying to get a list of files that contain one word, but not another word. To do that I call "rg -l foo" to get a list of files that I pass on to another call with "rg --files-without-match bar". The call looks something like this: rg -l foo | xargs -i -d '\n' rg --files-without-match bar {}

This doesn't work because --files-without-match cannot be used with a single file. The error message is " output kind PathWithoutMatch requires a file path". However I don't understand why that shouldn't be possible.
Maybe there's a better way to do this? If not I'd really appreciate it if that could be implemented.

@BurntSushi
Copy link
Owner

BurntSushi commented Nov 14, 2018 via email

@ShadowIce
Copy link
Author

If you need an example, use the ripgrep source code with this (it lists all files with an impl block, but no tests):
rg -l -g '*.rs' "impl " | xargs -i -d '\n' grep -L 'cfg(test)' {}

What I would like is to use rg for the second part as well, which probably would be: rg -l -g '*.rs' "impl " | xargs -i -d '\n' rg --files-without-match 'cfg\(test\)' {}

My use case is searching in C++ code for includes that are not needed, e.g. rg -l "#include <vector>" | xargs -i -d '\n' grep -L "vector<" {}

@BurntSushi
Copy link
Owner

BurntSushi commented Nov 14, 2018

Thanks. As a suggestion, your xargs use is a bit indiosyncratic. rg -l -g '*.rs' "impl " -0 | xargs -0 grep -L 'cfg(test)' is simpler.

Also, xargs is not needed for a reproduction. Here's a very simple example:

$ rg --files-without-match 'cfg(test)' src/main.rs
src/main.rs: output kind PathWithoutMatch requires a file path

$ rg --files-without-match 'cfg(test)' src/main.rs src/main.rs
src/main.rs
src/main.rs

This is definitely a bug. Thanks for reporting it!

@BurntSushi BurntSushi added the bug A bug. label Nov 14, 2018
@BurntSushi BurntSushi changed the title Feature request: Parameters --files-without-match / --files-with-matches should work with single file --files-without-match reports an error when used with a single file path Nov 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants