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

Flag not to split text file into lines #35

Merged
merged 2 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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