ack3
ack3 copied to clipboard
Make -x and --type mutually exclusive
The --type (and related --perl, --php, etc) flag has no effect when the -x flag is in use. We should make ack warn about this.
Here's the use case:
I was searching for files that use Test::Deep but don't actually use the cmp_bag function. So I used this:
ack Test::Deep -l | ack -x -L cmp_bag
Works just fine, but it gave me hits on plain text files, so I ran it again as
ack Test::Deep -l | ack -x -L cmp_bag --perl
The --perl has no effect because -x is effectively like specifying files on the command line, and the type limiters have no effect in that case. Instead, ack should have warned saying "Too bad, that won't work."
(The way to do this was to add --perl to the first ack invocation.)
ack Test::Deep -l --perl | ack -x -L cmp_bag
@petdance Ditto for --sort-files
Would it be possible to move where -x is used to allow -x and --perl to work together?
I agree that ack should warn about this, because I'm sure I've done this. But the use case is broader and can't always be fixed as follows:
(The way to do this was to add
--perlto the first ack invocation.)
This works if the thing you're piping from is ack. But sometimes you have another thing that lists files.
For instance, I would expect to be able to find perl files that are in source control by doing;
git ls-files | ack -x --perl foo
At the moment, I have to do something like
git ls-files | ack '\.p[ml]$' | ack -x foo
... which is somewhat more prone to user error.
Never mind that ack '\.p[ml]$' is not the same as ack --perl.
Also, not surprisingly, the use of git ls-files | ack -x --perl foo is what brought this up.
I'm slowly leaning towards the meta rule "the user knows what they're doing" should control here rather than "explicit files ignore filters" .
-x is not the same as user typing each of the files on the commandline.
One alternative is having a behavior flag for xargs-and-types that goes in user ackrc, selecting warn-and-ignore (default; as proposed in #241 (here)), fatal (plausible option to prevent wrong answers), or filter (as requested in #303 ).
A plausible alternative would be having a -f/-g variant that uses -x input, maybe call it -X, that applies --type filter to an xargs filename stream of names, that could be inserted between in a pipeline -
git ls-files | ack -X --perl | ack -x 'use Mo[ouse]*\b'
This would be consistent with our rule that -g re has to be pipelined not combined with ack re .