This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
I made this command as alias to cljdoc
in windows:
✅ Paste directly in cmd:
for /f %i in ('bb -Sdeps "{:deps {io.github.lispyclouds/bblgum {:git/sha \"b1b939ae5ae522a55499a8260b450e8898f77781\"}}}" -e "(require '[bblgum.core :as b]) (->> (apropos \"\") (clojure.string/join \"\n\") (b/gum :filter :in) :result first symbol)"') do @bb -e "(doc %i)"
✅ Batch file escaped version:
doskey cljdoc=FOR /F %%i in ('bb -Sdeps "{:deps {io.github.lispyclouds/bblgum {:git/sha \"b1b939ae5ae522a55499a8260b450e8898f77781\"}}}" -e "(require '[bblgum.core :as b]) (->> (apropos \"\") (clojure.string/join \"\n\") (b/gum :filter :in) :result first symbol)"') do @bb -e "(doc %%i)"
The simpler version without using gum
inside babashka:
✅ Paste directly in cmd:
FOR /F %i in ('bb -e "(doseq [item (apropos \"\")] (println item))" ^| gum filter') do @bb -e "(doc %i)"
❎ Batch file escaped version (not working):
doskey cljdoc=FOR /F %%i in ('bb -e "(doseq [item (apropos \"\")] (println item))" ^| gum filter') do @bb -e "(doc %%i)"
In linux, none of them are working, I tried:
❎ bb -e "(doseq [item (apropos \"\")] (println item))" | gum filter | bb "(doc *input*)"
❎ bb -Sdeps "{:deps {io.github.lispyclouds/bblgum {:git/sha \"b1b939ae5ae522a55499a8260b450e8898f77781\"}}}" -e "(require '[bblgum.core :as b]) (->> (apropos \"\") (clojure.string/join \"\n\") (b/gum :filter :in) :result first symbol doc)"
I saw source code of doc
it's a macro, is it why it is unable to read input, find-doc
works in above commands as its a function. Also, in windows too, linux like piped version wasn't working specifically for doc
but was working for find-doc
.
What is the correct way to pipe data specifically for macros like doc
?
And correct command to make it work (more likely the gum outside babashka version) on both platforms?
It's easier if you leave all the shell stuff out of the equation and try to repro in pure Clojure
doc
indeed is a macro and macros expect static input, in the case of doc
it is a symbol, like (doc whatever)
. (doc (slurp *in*))
doesn't work, as you say find-doc
would work since that is the function equivalent
but you can work around this using another macro, like here: https://github.com/babashka/babashka/blob/master/examples/random_doc.clj
ok, i'll try using another macro as shown in random-doc
and also inside a script instead of putting everything in string on shell 😅
I couldn't make use of random-doc
macro, to make get-doc
, everytime it just returned java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Named
, so ended up doing it manually:
(require '[bblgum.core :refer [gum]]
'[clojure.string :as str]
'[clojure.repl :as repl])
(defn filter-menu [input placeholder] (first (:result (gum :filter :in input :placeholder placeholder :fuzzy false))))
(defn print-doc [item-meta]
(println "-------------------------")
(let [namespace-value (str (:ns item-meta))
function-name (:name item-meta)
arg-list (:arglists item-meta)
doc-string (:doc item-meta)]
(println (str namespace-value "/" function-name))
(println arg-list)
(println doc-string)))
(let [item (filter-menu (str/join "\n" (repl/apropos "")) "Search documentation...")]
(if (nil? item)
(println "No documentation available.")
(print-doc (meta (resolve (symbol item))))))
This was get-doc
(I tried):
(require '[clojure.repl])
(defmacro get-doc [sym]
(if (:doc (meta (resolve sym)))
`(clojure.repl/doc ~sym)
`(println "No documentation available for" '~sym)))
(get-doc (symbol "clojure.core/diff")) ;; Error
Result from gum filter
is a String, and passing that to get-doc
gives this ClassCastException (clojure.lang.PersistentList cannot be cast to clojure.lang.Named)
which I was unable to fix, hence, made manual print-doc
function using metadata.if you want to pass a string then write (resolve (symbol the-string))
in the macro instead
I'm not passing a list to get-doc
I am passing string only, also I tried (resolve (symbol the-string))
too before and again right now, it prints exactly the same exception error. I'm also scratching my head on this:
`(defmacro get-doc [sym]
(if (:doc (meta (resolve (symbol sym))))
(clojure.repl/doc (resolve (symbol ~sym)))
(println "No documentation available for" '~sym)))`
Ok got it, it is passing as (symbol "clojure.core/diff")
, which is a list, sorry 😅, so I should pass a static input to a macro?
If I want to keep my library babashka compatible, what’s the best technique for that?
You could run your tests with babashka. I do that in my https://github.com/justone/bb-scripts project. I can run:
bb test
to run under Babashka or this:
clojure -M:clj:test
to run it under Clojure.
I have it set up this way so I can develop my babashka scripts in Clojure, but it should be applicable to your library.And then you have to keep the babashka included versions in sync manually in your deps, e.g.: https://github.com/justone/bb-scripts/blob/5f54bcec441622097b88539ddb809784925f6c67/deps.edn#L7 ? There’s no such thing as a maven parent with babashka libs, so that I could extend from that and then pull in libraries (e.g. babashka/fs) without specifying the version, as it’s provided by the parent?
@U05KWT468F8 re "parent", you can just make one dependency without any source which depends on other libraries.
bb print-deps
will print all libraries currently available in bb so you can generate a bb.edn
from that, but I'd remove any libraries you're not using to reduce the amount of deps in your lib