lizmat / App-Rak

21st century grep / find / ack / ag / rg on steroids
Artistic License 2.0
152 stars 7 forks source link

Add support for the grep like -f feature #23

Closed Zer0-Tolerance closed 1 year ago

Zer0-Tolerance commented 1 year ago

Can you plan to add a feature to read pattern from file as in -f in grep ?

lizmat commented 1 year ago

Would --patterns-from be a good (long) name for it? And I guess that --patterns-from=- would then read the patterns from STDIN.

I'm a bit puzzled about:

Read one or more newline separated patterns from file. Empty pattern lines match every input line. Newlines are not considered part of a pattern. If file is empty, nothing is matched.

particularly the "Empty pattern lines match every input line". So any empty line in such a file, would mean that all lines would be automatically selected? What would the use of the other patterns be then? I could see a use for just one empty line, though. Puzzled.

Zer0-Tolerance commented 1 year ago

the main use case from my perspective is to check for a list of regex or specific strings so I wouldn't mind to much about the "empty line" in this feature.

Zer0-Tolerance commented 1 year ago

thanks for adding --patterns-from it's great ! but I'm getting an error when I try to specify a regex in the file:

cat /tmp/pattern
111
abc
/^ab/
rak --patterns-from=/tmp/pattern /tmp/
A worker in a parallel iteration (hyper or race) initiated here:
  in sub show-results at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/sources/06D54E7B08D71050D35620285F06BBF9BAC471C3 (App::Rak) line 830
  in sub rak-results at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/sources/06D54E7B08D71050D35620285F06BBF9BAC471C3 (App::Rak) line 701
  in sub action-per-line at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/sources/06D54E7B08D71050D35620285F06BBF9BAC471C3 (App::Rak) line 2915
  in sub main at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/sources/06D54E7B08D71050D35620285F06BBF9BAC471C3 (App::Rak) line 423
  in block <unit> at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/resources/5A8CE6ED95A092BFB0EF7BA388399642ED16103A line 3
  in sub MAIN at /Users/.rakubrew/shims/rak line 3
  in block <unit> at /Users/.rakubrew/shims/rak line 1

Died at:
    No such method '!cursor_start' for invocant of type 'Str'
      in sub show-results at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/sources/06D54E7B08D71050D35620285F06BBF9BAC471C3 (App::Rak) line 830
      in sub rak-results at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/sources/06D54E7B08D71050D35620285F06BBF9BAC471C3 (App::Rak) line 701
      in sub action-per-line at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/sources/06D54E7B08D71050D35620285F06BBF9BAC471C3 (App::Rak) line 2915
      in sub main at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/sources/06D54E7B08D71050D35620285F06BBF9BAC471C3 (App::Rak) line 423
      in block <unit> at /Users/.rakubrew/versions/moar-2022.07/share/perl6/site/resources/5A8CE6ED95A092BFB0EF7BA388399642ED16103A line 3
      in sub MAIN at /Users/.rakubrew/shims/rak line 3
      in block <unit> at /Users/.rakubrew/shims/rak line 1
Zer0-Tolerance commented 1 year ago

with this file:

cat /tmp/pattern
^a.c
^1

you'll get the same error as above but if you got only a single regex in the file then it's working fine.

lizmat commented 1 year ago

Thanks for the report. I'll look at this tomorrow

lizmat commented 1 year ago

Fixed with 0.2.2.