What do people do for global bb tasks these days? I found a tip from @borkdude on ClojureVerse from a while ago, and did this. Works beautifully.
I’m not sure loc belongs as a global task, but I will try maintain it and see if it makes sense. From a project I care a lot about (yes, #epupp):
❯ bbg loc
229 text files.
206 unique files.
72 files ignored.
v 2.00 T=0.13 s (1185.0 files/s, 290076.2 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
ClojureScript 116 3820 2975 24617
CSS 5 370 165 1983
JSON 4 0 0 1794
Clojure 7 109 71 981
HTML 13 69 28 658
YAML 3 62 5 337
ClojureC 1 24 2 263
JavaScript 5 28 62 168
SVG 3 0 4 28
Dockerfile 1 12 17 25
-------------------------------------------------------------------------------
SUM: 158 4494 3329 30854
------------------------------------------------------------------------------- Completions, This gives me one-level options completion:
_bbg() {
if (( CURRENT == 2 )); then
local tasks=(`bbg tasks | tail -n +3 | cut -f1 -d ' '`)
compadd -a tasks
else
local task="${words[2]}"
local opts=(`bbg tasks | grep "^${task} " | grep -oE '\-\-[a-z-]+'`)
if (( ${#opts} )); then
compadd -a opts
fi
fi
}
compdef _bbg bbg
Given that the options are mentioned in the doc strings:
❯ bbg tasks
The following tasks are available:
loc Count lines of code (excludes generated files, markdown, vendor)
clj Manage clojure installs. Options: --status, --update, --update-deps-clj, --use-deps-clj, --use-clojure
config Manage config repos. Options: --status, --save
java Manage Java versions. Options: --status, --version <major|latest>My current system sucks! I have some conventions around creating scripts with Babashka, prefixing executables with ,, and the collection here: https://github.com/teodorlu/shed
So I would be happy to consider something different 😅
One observation: your approach would build a classpath with all the dependencies for all the tasks in order to execute any of the tasks.
Not sure if that's a downside. It lets you work on all the tasks from within a single REPL. Perhaps that's just fine?
Q: would having all global scripts go via babashka tasks prevent individual tasks from providing their own shell completion?
Nonetheless, I would love to have a nice collection of system-wide Babashka scripts that are easy to work on and easy to improve. Requirements for me: • No build step • Can work on scripts from the REPL as easily as run them
I have updated the recipe a bit since I posted this. Using --config instead of mucking with the current directory. About the tab completion, that’s also a thing I do differently now. Local tasks have separate completion, if that’s what you wondered? Here’s my updated recipe, including some tasks: https://github.com/PEZ/my-bbg
> Local tasks have separate completion, if that’s what you wondered? Yep, that was my concern! Thank you, I'll have a look!
Hi I try to use babashka.http to do some requests but as they are failing i probably made an error. Is it possible print out the exact request an (http/post ... ) makes. I'm running my code on babashka
Yes there's a debug option for it
I think
Or Java net http has an option for it
In the documentation i found: "`-Djdk.httpclient.HttpClient.log=errors,requests,headers,frames[controldata:window:all..],content,ssl,trace,channel"` but as far as i can tell i can't add this option to an bb nrepl?
a client can be passed as :client, or client can also be a function, so you can sort of skip actually making the request altogether:
user=> (babashka.http-client/get " " {:client identity :raw true})
{:client #object[clojure.core$identity 0x7c556abb "clojure.core$identity@7c556abb"], :raw true, :uri #object[java.net.URI 0x7be5084d " "], :method :get, :headers nil}
...whether that's useful or not will probably depend on the nature of the failureyes it helped, i was interpreting the oauth options wrong and had a Bearer Bearer 🙂
@borkdude and @highpressurecarsalesm thanks for your help!
Brilliant, we should document this ;)
you can start the bb nrepl with this btw:
bb -Djdk.httpclient.HttpClient.log=... nrepl-serverregarding docs - I was mostly going off the http-client API doc, but I did notice that :raw is missing as an opt there. If I open a PR for doc updates, would you prefer just adding :raw ? How would you feel about a small example in the readme using identity or something as a client?
oh sorry I didn't know it was already documented, responded from phone. all good then.
@borkdude i'm not able to run bb with the log statement: > ❯ bb -Djdk.httpclient.HttpClient.log=errors,requests,headers,frames[controldata:window:all..],content,ssl,trace,channel nrepl > zsh: no matches found: -Djdk.httpclient.HttpClient.log=errors,requests,headers,frames[controldata:window:all..],content,ssl,trace,channel
You’re running into.a shell quoting issue or something. Is your argument on the same line? Anyway this is a zsh syntax problem
with bash i get a similar problem
bash-5.3$ bb -Djdk.httpclient.HttpClient.log=errors,requests,headers,frames[:control:data:window:all..],content,ssl,trace,channel nrepl
----- Error --------------------------------------------------------------------
Type: java.lang.Exception
Message: File does not exist: nreplSorry it was a user error...
bb "-Djdk.httpclient.HttpClient.log=errors,requests,headers,frames[:control:data:window:all..],content,ssl,trace,channel" nrepl-serverworks fine