I’ve been thinking for a while that it would be super great to have a socket repl/unrepl client geared towards shell and shell script usage.
My hands have been itching to get started on this, but I really have enough going on already, so I’m just going to put this up here and hope that someone takes the bait
Let’s call this hypothetical command line utility
sokclj. You could call it like this
sokclj -H localhost:5555 -e '(my-app.tasks/clear-cache)'
Now you might argue that you can do the same thing with
telnet, and indeed you can
nc localhost 5555 <<< '(my-app.tasks/clear-cache)'
The difference would be that the
sokclj version hooks up STDOUT and STDERR separately, and that it exits with a non-zero exit code in case of an exception, that’s why basing it on unrepl would make sense. But also, we could pack it with a lot of useful command line flags.
# send the file to the REPL, connect to default localhost:5555 sokclj my_script.clj # mirror Clojure's -m flag to invoke a -main function sokclj -m my-app.tasks.do-thing arg1 arg2 # mirror Ruby's (or sed's) -n switch, read line per line from STDIN, and assign each line to $ sokclj -n '(println (clojure.string/uppercase $))' # Same as above, but run `prn` on the result after each iteration sokclj -p '(clojure.string/uppercase $)' # require a namespace sokclj -r my-app.stuff -e '(my-app.stuff/do-it)'
I can also imagine options for dealing with EDN input/output (or other formats).
It would have to boot fast, so it can’t be written in Clojure, but it could use ClojureScript and e.g. Node, or Lumo. Maybe some of these features could be added to Unravel (wdyt @pesterhazy?).
Can anyone else imagine a need for this? Calling things e.g. from Cron jobs or Ansible scripts?