Skip to content

Commit 2cadc2e

Browse files
committed
Be more generous when extracting first sentence
1 parent a292228 commit 2cadc2e

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* You may now enter `-h` or `--help` after a group to get help for just that group
2424
* Tool help output has been reordered, with top-level tool commands first (previously, those were in a "Builtin" group and listed last)
2525
* Tool help now displays just top-level commands by default (add --full to list nested commands)
26+
* When extracting the first sentence as the single-line index, embedded period are no longer considered the end of the sentence
2627
* net.lewisship.cli-tools
2728
* New `command-path` function returns a composed string of the tool name and command path
2829
* `dispatch` function has new options:

src/net/lewisship/cli_tools/impl.clj

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,17 @@
128128
(when repeatable
129129
(if optional "*" "+")))))
130130

131-
(defn- first-sentence
131+
(defn first-sentence
132132
[s]
133133
(when (string? s)
134-
(-> s
135-
string/trim
136-
string/split-lines
137-
first
138-
(string/split #"\s*\.")
139-
first
140-
string/trim)))
134+
(let [s' (-> s
135+
string/trim
136+
string/split-lines
137+
first
138+
(string/split #"\s*\.(?:\s+|$)")
139+
first)]
140+
(when-not (string/blank? s')
141+
s'))))
141142

142143
(defn- indentation-of-line
143144
[line]

test/net/lewisship/cli_tools/impl_test.clj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,17 @@
190190
'([:cyan "alpha"] ", "
191191
[:cyan "bravo"] ", "
192192
[:cyan "charlie"] " (or one other)"))))
193+
194+
(deftest first-sentence
195+
(are [s expected] (= expected (impl/first-sentence s))
196+
197+
" Quick, Simple " "Quick, Simple"
198+
199+
"\n\n The first.\nThe second." "The first"
200+
201+
"In namespace x.y.z, we do this thing." "In namespace x.y.z, we do this thing"
202+
203+
nil nil
204+
205+
"" nil
206+
))

0 commit comments

Comments
 (0)