Skip to content

Commit

Permalink
add support for throwing on nzec
Browse files Browse the repository at this point in the history
  • Loading branch information
joakimen committed Feb 3, 2024
1 parent 38cd68a commit 75ae531
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/fzf/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
(s/def :fzf/tac boolean?)
(s/def :fzf/case-insensitive boolean?)
(s/def :fzf/exact boolean?)
(s/def :fzf/throw boolean?)

(s/def :fzf/opts
(s/and (s/keys
Expand All @@ -36,7 +37,8 @@
:fzf/height
:fzf/tac
:fzf/case-insensitive
:fzf/exact])
:fzf/exact
:fzf/throw])
#(not (and (:preview %) (:preview-fn %)))))

(s/def :fzf/args sequential?)
Expand All @@ -61,6 +63,7 @@
- tac: Bool, reverse the order of the input
- case-insensitive: Bool, toggle case-insensitive search (default: smart-case)
- exact: Bool, toggle exact search (default: fuzzy)
- throw: Bool, throw when no candidates were selected (default: return nil)
`args`: Input arguments to fzf (optional, list of strings)
Expand Down
6 changes: 4 additions & 2 deletions src/fzf/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@
(start-preview-fn-server port-promise preview-fn)
(ByteArrayOutputStream.))] ; any proper Closeable thing will do.
(let [multi (:multi opts)
throw-on-nzec (:throw opts)
{:keys [cmd opts]} (parse-opts opts args (when preview-fn @port-promise))
{:keys [out exit]} @(p/process cmd opts)]
(if (zero? exit)
(cond-> (str/trim out)
multi str/split-lines)
nil)))))
multi str/split-lines)
(if throw-on-nzec (throw (ex-info "No candidates were selected" {:babashka/exit 1}))
nil))))))
3 changes: 2 additions & 1 deletion test/fzf/impl_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
:header {:header-str "header-text"
:header-lines 2
:header-first true}
:height "10%"}
:height "10%"
:throw true}
[])))))
(t/testing "adding :preview-fn produces command string with inline bb netcat script"
(t/is (= ["fzf" "--preview" (i/bbnc-preview-command 12345)]
Expand Down

0 comments on commit 75ae531

Please sign in to comment.