-
-
Save hkupty/8d1e8199cdb0d98dc332e4c9ec684cd1 to your computer and use it in GitHub Desktop.
jq for edn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#_( | |
DEPS='' | |
OPTS=' | |
-J-Xms256m -J-Xmx256m -J-client | |
' | |
exec clojure $OPTS -Sdeps "$DEPS" "$0" "$@" | |
) | |
(require '[clojure.edn :as edn] | |
'[clojure.string :as str]) | |
(def in (slurp *in*)) | |
(defn ->out [ret] | |
(cond | |
(coll? ret) (run! println ret) | |
:else (println ret))) | |
(def query | |
*command-line-args*) | |
(defn ->kw [s] | |
(keyword (clojure.string/replace s #":" ""))) | |
(defn lex [obj] | |
(if (str/starts-with? obj ":") | |
(->kw obj) | |
(resolve (symbol obj)))) | |
(def apply-fns (reduce comp (reverse (map lex *command-line-args*)))) | |
(some->> in | |
(edn/read-string) | |
apply-fns | |
->out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment