Skip to content

Commit

Permalink
Flag not to split text file into lines (#35)
Browse files Browse the repository at this point in the history
* feat: flag not to split the text file into lines
* mention a flag to the changelog
  • Loading branch information
dainiusjocas authored Feb 1, 2021
1 parent fb10623 commit dcc3807
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For a list of breaking changes, check [here](#breaking-changes).

- Stable Clojure release 1.10.2
- Remove redundant options from native-image building script
- Flag to search in whole files

## v2021.01.24

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Supported options:
--post-tags POST_TAGS A string that the highlighted text is wrapped in, use in conjunction with --pre-tags
--excludes EXCLUDES A GLOB that filters out files that were matched with a GLOB
--skip-binary-files If a file that is detected to be binary should be skipped. Available for Linux and MacOS only.
--[no-]split If a file (or STDIN) should be split by newline.
-h, --help
```
Expand Down
2 changes: 2 additions & 0 deletions src/lmgrep/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
[nil "--excludes EXCLUDES" "A GLOB that filters out files that were matched with a GLOB"]
[nil "--skip-binary-files" "If a file that is detected to be binary should be skipped. Available for Linux and MacOS only."
:default false]
[nil "--[no-]split" "If a file (or STDIN) should be split by newline."
:default true]
;[nil "--slop SLOP" "How far can be words from each other"
; :parse-fn #(Integer/parseInt %)
; :default 0]
Expand Down
10 changes: 7 additions & 3 deletions src/lmgrep/grep.clj
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@
highlighter-fn (lucene/highlighter dictionary)]
(if files-pattern
(doseq [path (fs/get-files files-pattern options)]
(with-open [rdr (io/reader path)]
(match-lines highlighter-fn path (line-seq rdr) options)))
(if (:split options)
(with-open [rdr (io/reader path)]
(match-lines highlighter-fn path (line-seq rdr) options))
(match-lines highlighter-fn path [(slurp path)] options)))
(when (.ready ^Reader *in*)
(match-lines highlighter-fn nil (line-seq (BufferedReader. *in*)) options)))))
(if (:split options)
(match-lines highlighter-fn nil (line-seq (BufferedReader. *in*)) options)
(match-lines highlighter-fn nil [(str/trim (slurp *in*))] options))))))

(comment
(lmgrep.grep/grep "opt" "**.md" {:format :edn})
Expand Down

0 comments on commit dcc3807

Please sign in to comment.