This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-15
Channels
- # announcements (8)
- # architecture (9)
- # autochrome-github (1)
- # babashka (48)
- # beginners (55)
- # calva (36)
- # cider (16)
- # clj-commons (1)
- # clj-kondo (38)
- # cljs-dev (44)
- # cljsrn (1)
- # clojure (164)
- # clojure-europe (35)
- # clojure-nl (2)
- # clojure-norway (10)
- # clojure-uk (23)
- # clojurescript (50)
- # conjure (24)
- # core-async (1)
- # cryogen (2)
- # cursive (38)
- # datalevin (11)
- # datascript (2)
- # datomic (13)
- # duct (1)
- # emacs (16)
- # events (12)
- # exercism (3)
- # figwheel-main (7)
- # fulcro (26)
- # honeysql (5)
- # integrant (1)
- # jobs (3)
- # kaocha (6)
- # lsp (72)
- # malli (22)
- # nextjournal (35)
- # nrepl (1)
- # off-topic (34)
- # pathom (5)
- # polylith (8)
- # portal (40)
- # re-frame (14)
- # reagent (42)
- # reitit (1)
- # releases (1)
- # remote-jobs (1)
- # reveal (9)
- # sci (2)
- # shadow-cljs (13)
- # sql (3)
- # tools-deps (33)
- # vim (25)
How would I pass a JSON string as an arg to a clojure -X:bench
execution when that JSON is generated by a sub-command? Example:
clojure -X:bench :json "$(my_cmd --blah)"
I keep getting errors like:
Unreadable arg: "{\"blah\": 1}"
Which suggest to me that the quoting is wrongprobably tricky
you need the outer double quotes for the inner to be evaluated
I can pass the JSON in manually like this:
clojure -X:bench :json-plan '"{\"blah\": 1}"'
And it works, but the single quotes seem to preclude the sub-commandbut you also need explicit double quotes
so yeah, something like that
or pipe into stdin and read that :)
or put it in a file and pass the file as the arg. would be helpful when keeping interesting test cases around
we have an interesting test runner that can take a namespace, a list of namespaces, or a directory and run all tests contained in those. You could do similar logic so you can pass a file, a list of files, or a directory. clj -X:bench -json examples/weird/funky.json
or clj -X:bench -json examples/stress
or what have you. Or you can put different keys for the different types
@cjsauer Try '"'$(my_cmd --blah)'"'
-- although that may still not work with the internal quoting.
(but, yeah, reading JSON from stdin is likely to be easier than wrangling shell quoting)
@seancorfield The outer single quotes will prevent the $() from being "eval-ed"
No it won't.
(! 678)-> echo '"'$(clojure -Spath)'"'
"src:/Users/sean/.m2/repository/org/clojure/clojure/1.11.0-beta1/clojure-1.11.0-beta1.jar:/Users/sean/.m2/repository/org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar:/Users/sean/.m2/repository/org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar"
(but it does not handle quotes in the content unfortunately)
(! 754)-> echo '"'$(cat deps.edn)'"'
"{:aliases { :hiccup {:extra-deps {hiccup/hiccup {:mvn/version "RELEASE"}}} :exec {:exec-fn [a b] :ns-default exec} :build {:extra-deps {io.github.seancorfield/build-clj {:local/root "/Developer/workspace/build-clj"}}} :build-slim {:extra-deps {io.github.seancorfield/build-clj {:local/root "/Developer/workspace/build-clj/slim"}}} :dev {:jvm-opts ["-Dclojure.compile.warn-on-reflection=true"]}}}"
so you'd need to pipe it through some sed
escaping or some such...(! 755)-> echo '"'$(cat deps.edn|sed 's;";\\";g')'"'
"{:aliases { :hiccup {:extra-deps {hiccup/hiccup {:mvn/version \"RELEASE\"}}} :exec {:exec-fn [a b] :ns-default exec} :build {:extra-deps {io.github.seancorfield/build-clj {:local/root \"/Developer/workspace/build-clj\"}}} :build-slim {:extra-deps {io.github.seancorfield/build-clj {:local/root \"/Developer/workspace/build-clj/slim\"}}} :dev {:jvm-opts [\"-Dclojure.compile.warn-on-reflection=true\"]}}}"
@seancorfield Ah, I see!