Skip to content

Commit

Permalink
Use pprint from util
Browse files Browse the repository at this point in the history
  • Loading branch information
eval committed Feb 8, 2023
1 parent 1f481b6 commit 0b676fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
21 changes: 9 additions & 12 deletions bbin
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,6 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
[selmer.util :as selmer-util])
(:import (java.util.jar JarFile)))

(defn- pprint [x _]
(pprint/pprint x))

(defn- local-lib-path [script-deps]
(let [lib (key (first script-deps))
coords (val (first script-deps))]
Expand Down Expand Up @@ -521,9 +518,9 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
[path contents dry-run?]
(let [path-str (str path)]
(if dry-run?
(pprint {:script-file path-str
:script-contents contents}
dry-run?)
(util/pprint {:script-file path-str
:script-contents contents}
dry-run?)
(do
(spit path-str contents)
(when-not util/windows? (sh ["chmod" "+x" path-str]))
Expand All @@ -535,7 +532,7 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
(let [http-url (:script/lib cli-opts)
script-deps {:bbin/url http-url}
header {:coords script-deps}
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
script-name (or (:as cli-opts) (http-url->script-name http-url))
script-contents (-> (slurp (:bbin/url script-deps))
(insert-script-header header))
Expand All @@ -547,7 +544,7 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
(let [file-path (str (fs/canonicalize (:script/lib cli-opts) {:nofollow-links true}))
script-deps {:bbin/url (str "file://" file-path)}
header {:coords script-deps}
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
script-name (or (:as cli-opts) (file-path->script-name file-path))
script-contents (-> (slurp file-path)
(insert-script-header header))
Expand Down Expand Up @@ -578,7 +575,7 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
main-ns (jar->main-ns tmp-jar-path)
cached-jar-path (fs/file (util/jars-dir cli-opts) (str script-name ".jar"))
_ (fs/move tmp-jar-path cached-jar-path {:replace-existing true})
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
script-edn-out (with-out-str
(binding [*print-namespace-maps* false]
(clojure.pprint/pprint header)))
Expand All @@ -600,7 +597,7 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
main-ns (jar->main-ns file-path)
script-deps {:bbin/url (str "file://" file-path)}
header {:coords script-deps}
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
script-name (or (:as cli-opts) (file-path->script-name file-path))
cached-jar-path (fs/file (util/jars-dir cli-opts) (str script-name ".jar"))
script-edn-out (with-out-str
Expand Down Expand Up @@ -666,7 +663,7 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
header' (if (#{::no-lib} lib)
{:coords {:bbin/url (str "file://" (get-in header [:coords :local/root]))}}
header)
_ (pprint header' cli-opts)
_ (util/pprint header' cli-opts)
_ (when-not (#{::no-lib} lib)
(deps/add-deps {:deps script-deps}))
script-root (fs/canonicalize (or (get-in header [:coords :local/root])
Expand Down Expand Up @@ -760,7 +757,7 @@ WARNING: - Set the BABASHKA_BBIN_BIN_DIR env variable to \"$HOME/.babashka/bbi
(select-keys cli-opts [:mvn/version])}
header {:lib (key (first script-deps))
:coords (val (first script-deps))}
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
_ (deps/add-deps {:deps script-deps})
script-root (fs/canonicalize (or (:local/root cli-opts) (local-lib-path script-deps)) {:nofollow-links true})
script-name (or (:as cli-opts) (second (str/split (:script/lib cli-opts) #"/")))
Expand Down
21 changes: 9 additions & 12 deletions src/babashka/bbin/scripts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
[selmer.util :as selmer-util])
(:import (java.util.jar JarFile)))

(defn- pprint [x _]
(pprint/pprint x))

(defn- local-lib-path [script-deps]
(let [lib (key (first script-deps))
coords (val (first script-deps))]
Expand Down Expand Up @@ -259,9 +256,9 @@
[path contents dry-run?]
(let [path-str (str path)]
(if dry-run?
(pprint {:script-file path-str
:script-contents contents}
dry-run?)
(util/pprint {:script-file path-str
:script-contents contents}
dry-run?)
(do
(spit path-str contents)
(when-not util/windows? (sh ["chmod" "+x" path-str]))
Expand All @@ -273,7 +270,7 @@
(let [http-url (:script/lib cli-opts)
script-deps {:bbin/url http-url}
header {:coords script-deps}
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
script-name (or (:as cli-opts) (http-url->script-name http-url))
script-contents (-> (slurp (:bbin/url script-deps))
(insert-script-header header))
Expand All @@ -285,7 +282,7 @@
(let [file-path (str (fs/canonicalize (:script/lib cli-opts) {:nofollow-links true}))
script-deps {:bbin/url (str "file://" file-path)}
header {:coords script-deps}
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
script-name (or (:as cli-opts) (file-path->script-name file-path))
script-contents (-> (slurp file-path)
(insert-script-header header))
Expand Down Expand Up @@ -316,7 +313,7 @@
main-ns (jar->main-ns tmp-jar-path)
cached-jar-path (fs/file (util/jars-dir cli-opts) (str script-name ".jar"))
_ (fs/move tmp-jar-path cached-jar-path {:replace-existing true})
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
script-edn-out (with-out-str
(binding [*print-namespace-maps* false]
(clojure.pprint/pprint header)))
Expand All @@ -338,7 +335,7 @@
main-ns (jar->main-ns file-path)
script-deps {:bbin/url (str "file://" file-path)}
header {:coords script-deps}
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
script-name (or (:as cli-opts) (file-path->script-name file-path))
cached-jar-path (fs/file (util/jars-dir cli-opts) (str script-name ".jar"))
script-edn-out (with-out-str
Expand Down Expand Up @@ -404,7 +401,7 @@
header' (if (#{::no-lib} lib)
{:coords {:bbin/url (str "file://" (get-in header [:coords :local/root]))}}
header)
_ (pprint header' cli-opts)
_ (util/pprint header' cli-opts)
_ (when-not (#{::no-lib} lib)
(deps/add-deps {:deps script-deps}))
script-root (fs/canonicalize (or (get-in header [:coords :local/root])
Expand Down Expand Up @@ -498,7 +495,7 @@
(select-keys cli-opts [:mvn/version])}
header {:lib (key (first script-deps))
:coords (val (first script-deps))}
_ (pprint header cli-opts)
_ (util/pprint header cli-opts)
_ (deps/add-deps {:deps script-deps})
script-root (fs/canonicalize (or (:local/root cli-opts) (local-lib-path script-deps)) {:nofollow-links true})
script-name (or (:as cli-opts) (second (str/split (:script/lib cli-opts) #"/")))
Expand Down

0 comments on commit 0b676fd

Please sign in to comment.