Should I use boot or tools.deps to build command line applications?

Hello!

I’ve been experimenting with using clojure for shebang scripting myself. I want something that is totally self-contained. That is, it doesn’t need a separate deps.edn file.

Here’s what I’ve come up with. It lets you have multi-line deps maps contained in the file. You can execute any Clojure code you want.

#!/usr/bin/env bash
#_(

cat "$0" | clojure -Sdeps '
{:deps {clj-time {:mvn/version "0.14.2"}}}
' -

exit $?
#_nil)

(println "Hello!")

(require '[clj-time.core :as t])

(prn (str (t/now)))

The biggest downside is that it is quite a hack. It uses the fact that #_ in Clojure creates a commented (ignored) expression, while # starts a comment in bash. However, for a bash script, it’s pretty good. I’ve got this one on my path, set to executable, and it runs great from the command line.

> cljtest

and

> sh ~/bin/cljtest

both work.

I’m all ears for comments.

Rock on!
Eric

2 Likes