ack3 icon indicating copy to clipboard operation
ack3 copied to clipboard

-x and --type=format options should be mutex

Open petdance opened this issue 2 years ago • 4 comments

If I have something like this:

cat filelist.txt | ack -x --noperl

I will be surprised that the --noperl does nothing because -x already knows it is getting files from stdin, and does no filtering. I should get a mutex warning that -x and --noperl can't be used together.

petdance avatar Mar 16 '23 14:03 petdance

this is consistent with the behavior of ack -f --noperl *.pl

but one can argue that according to Principle of Least Surprise, we're consistently wrong, that file type filters should apply to (supposedly) explicit file lists (including -x xargs ).

n1vux avatar Mar 16 '23 20:03 n1vux

@n1vux - adding my vote on feeling consistently surprised by this feature.

Would it make more sense if we consider CLI arguments are really intended to bypass --ignore rules (especially those that are default or came from .ackrc), and not the --type/-T arguments that are more commonly specified at the time of the query?

This would make the following invocations equivalent, which seems clean to me. Currently, only the single one diverges from the rest of them.

ack -f --type=json | ack -x foo
ack -f | ack -x --type=json foo         # doesn't work today :(
ack --type=json foo

(caveat - only the last form can handle filenames with newlines in them 😞. Would it be pushing it to ask for find's --files0-from or xarg's -0/--null while we're here?)

Also, it'd be really nice if git ls-files | ack -x --type=json foo DWYM.

jakebman avatar Mar 26 '23 16:03 jakebman

ack -f | ack -x --type=json foo # doesn't work today :(

Please, don't conflate "doesn't work" with "doesn't do what I want it to do." ack -x works exactly as I intended it.

petdance avatar Mar 26 '23 23:03 petdance

I've added a new ticket #368 for discussing a new flag that could act like -x but obey the type filters.

petdance avatar Mar 26 '23 23:03 petdance