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

Arguments silently ignored in filter mode #270

Open
rdpate opened this issue Oct 9, 2014 · 3 comments
Open

Arguments silently ignored in filter mode #270

rdpate opened this issue Oct 9, 2014 · 3 comments

Comments

@rdpate
Copy link

rdpate commented Oct 9, 2014

Ack silently ignores given filenames in filter mode. Expected behavior is to either ignore stdin (this is what grep does), search the specified arguments in addition to stdin, or warn/error. Actual behavior is to silently ignore the arguments. Examples:

$ cat file
xbyz
$ ack b. file  # as expected
xbyz
$ echo abcd | ack b. file  # bug-1
abcd
$ ack b. file --filter  # bug-2
$ echo abcd | ack b. file --filter  # bug-3
$ echo abcd | ack b. file /dev/stdin --nofilter  # as expected
file
1:xbyz

/dev/stdin
1:abcd
$

Tested against http://beyondgrep.com/ack-2.14-single-file on Ubuntu 14.04.

The last example, with /dev/stdin, doesn't make sense in isolation. I started with "-" instead, then found out ack doesn't treat "-" to mean "read stdin". I didn't think that warranted a separate issue, but any fix to this bug could address that too. (edit: it was a deeper problem than I expected, see #269)

$ ack b. - <file
ack: -: No such file or directory
@hoelzro
Copy link

hoelzro commented Oct 9, 2014

@rdpate Thanks for all of the time and effort you've spent investigating this! I think @petdance and I are going to have a discussion involving the community on what the right way to handle these sorts of things is.

@rdpate
Copy link
Author

rdpate commented Oct 10, 2014

Another option to the three for expected behavior I listed above: use the presence/absence of --[no]filter to determine what to do. Specifically:

  • echo abcd | ack b. file
    • bug-1 above
    • I would ignore stdin, similar to grep
  • ack b. file --filter
    • bug-2 above
    • I would read stdin and file, in that order, even if stdin is a tty
      • which adds using arguments to current behavior, instead of ignoring them
  • echo abcd | ack b. file --filter
    • bug-3 above
    • I would read stdin and file, in that order
  • echo abcd | ack b. file --nofilter
    • existing behavior is ignore stdin and read file
    • I would keep existing

In fact, if my suggested behavior was adopted, then the --filter option can be removed. Instead of using --nofilter, you would instead redirect stdin from </dev/null. Instead of --filter, you would use "-" or "/dev/stdin". (Whenever I say /dev/stdin, I really mean to say also allow "-" if ack is changed to interpret it as stdin, since I know /dev/stdin isn't universal.)

The quick "type tool | ack pat in a terminal" behavior is preserved -- though a typo of "pat" being more than one word would not be a warning/error, it should be quickly identified by the user because the second half of a pattern is unlikely to be a file ack can open. In a script, you would be required to either redirect stdin or specify "." -- but no warning could be given if you didn't.

This has breaking changes per-project/user .ackrc using --[no]filter, but I think such would be acceptable as I don't imagine this option is ever used in .ackrc.

Do you have a system in place for deprecating --[no]filter? Or should it just be removed, giving an error if specified? I'd like to try my hand at implementing this.

@rdpate
Copy link
Author

rdpate commented Oct 10, 2014

I'd like to try my hand at implementing this.

Twelve hours later... at least I know some perl now. :) Please let me know if I wrote non-idiomatic code, I tried to follow project conventions. In particular, using scalar @a == 1 to test array length seemed weird, but I couldn't find anything better.

@petdance petdance transferred this issue from beyondgrep/ack2 Sep 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants