From 3c5581fa3478f889433a1403bbe7b3bdf11c3cdb Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Tue, 10 Dec 2019 09:44:41 +0100 Subject: [PATCH] [#147] Add cheshire --- README.md | 6 ++++-- project.clj | 3 ++- src/babashka/impl/cheshire.clj | 14 ++++++++++++++ src/babashka/main.clj | 7 +++++-- 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 src/babashka/impl/cheshire.clj diff --git a/README.md b/README.md index ea8289aa..b5d2fba6 100644 --- a/README.md +++ b/README.md @@ -151,8 +151,9 @@ Everything after that is bound to *command-line-args*. The `clojure.core` functions are accessible without a namespace alias. The following namespaces are required by default and available through the -pre-defined aliases. You may use `require` + `:as` and/or `:refer` on these -namespaces. If not all vars are available, they are enumerated explicitly. +pre-defined aliases in the `user` namespace. You may use `require` + `:as` +and/or `:refer` on these namespaces. If not all vars are available, they are +enumerated explicitly. - `clojure.string` aliased as `str` - `clojure.set` aliased as `set` @@ -169,6 +170,7 @@ namespaces. If not all vars are available, they are enumerated explicitly. aliased as `conch` - [`clojure.tools.cli`](https://github.com/clojure/tools.cli) aliased as `tools.cli` - [`clojure.data.csv`](https://github.com/clojure/data.csv) aliased as `csv` +- [`cheshire.core`](https://github.com/dakrone/cheshire) aliased as `json` The following Java classes are available: diff --git a/project.clj b/project.clj index d87c4355..2c27951a 100644 --- a/project.clj +++ b/project.clj @@ -14,7 +14,8 @@ [borkdude/edamame "0.0.9-alpha.2"] [org.clojure/core.async "0.4.500"] [org.clojure/tools.cli "0.4.2"] - [org.clojure/data.csv "0.1.4"]] + [org.clojure/data.csv "0.1.4"] + [cheshire "5.9.0"]] :profiles {:test {:dependencies [[clj-commons/conch "0.9.2"]]} :uberjar {:global-vars {*assert* false} :jvm-opts ["-Dclojure.compiler.direct-linking=true" diff --git a/src/babashka/impl/cheshire.clj b/src/babashka/impl/cheshire.clj new file mode 100644 index 00000000..21faa7ba --- /dev/null +++ b/src/babashka/impl/cheshire.clj @@ -0,0 +1,14 @@ +(ns babashka.impl.cheshire + {:no-doc true} + (:require [cheshire.core :as json])) + +(def cheshire-core-namespace + {'encode json/encode + 'generate-string json/generate-string + 'encode-stream json/encode-stream + 'generate-stream json/generate-stream + 'encode-smile json/encode-smile + 'generate-smile json/generate-smile + 'decode json/decode + 'parse-string json/parse-string + 'decode-smile json/decode-smile}) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 488f983c..73ae4579 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -2,6 +2,7 @@ {:no-doc true} (:require [babashka.impl.async :refer [async-namespace]] + [babashka.impl.cheshire :refer [cheshire-core-namespace]] [babashka.impl.clojure.core :refer [core-extras]] [babashka.impl.clojure.java.io :refer [io-namespace]] [babashka.impl.clojure.stacktrace :refer [print-stack-trace]] @@ -215,7 +216,8 @@ Everything after that is bound to *command-line-args*.")) io clojure.java.io conch me.raynes.conch.low-level async clojure.core.async - csv clojure.data.csv} + csv clojure.data.csv + json cheshire.core} :namespaces {'clojure.core (assoc core-extras '*command-line-args* command-line-args) 'clojure.tools.cli tools-cli-namespace @@ -227,7 +229,8 @@ Everything after that is bound to *command-line-args*.")) 'clojure.java.io io-namespace 'me.raynes.conch.low-level conch-namespace 'clojure.core.async async-namespace - 'clojure.data.csv csv/csv-namespace} + 'clojure.data.csv csv/csv-namespace + 'cheshire.core cheshire-core-namespace} :bindings {'java.lang.System/exit exit ;; override exit, so we have more control 'System/exit exit} :env env