From 6719349ee036d344bb4c36d6004ae70139d780fd Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Fri, 22 Jul 2022 14:59:13 -0700 Subject: [PATCH 01/25] Add support for deps-based templates --- neil | 33 +++++++++++++++++++++++++++------ src/babashka/neil.clj | 33 +++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/neil b/neil index 2f58658..0b48275 100755 --- a/neil +++ b/neil @@ -20,15 +20,13 @@ (require '[babashka.classpath :as cp] '[babashka.cli :as cli] '[babashka.curl :as curl] + '[babashka.deps :as deps] '[babashka.fs :as fs] '[borkdude.rewrite-edn :as r] '[cheshire.core :as cheshire] '[clojure.edn :as edn] '[clojure.string :as str]) -;; deps-new reads classpath from property -(System/setProperty "java.class.path" (cp/get-classpath)) - (def spec {:lib {:desc "Fully qualified library name."} :version {:desc "Optional. When not provided, picks newest version from Clojars or Maven Central."} :sha {:desc "When provided, assumes lib refers to Github repo."} @@ -380,6 +378,11 @@ :target-dir :overwrite + ; template deps overrides + :local/root + :git/url + :git/sha + ; optional overrides :artifact/id :description @@ -397,11 +400,29 @@ :user :version]) +(defn- built-in-template? [template] + (contains? (set (map name (keys (ns-publics 'org.corfield.new)))) template)) + +(defn- github-repo-url [lib] + (str "https://github.com/" (clean-github-lib lib))) + +(defn- add-template-deps [template opts] + (let [lib (edn/read-string template) + local-root (:local/root opts)] + (if local-root + (deps/add-deps {:deps {lib {:local/root local-root}}}) + (let [url (or (:git/url opts) (github-repo-url lib)) + sha (or (:git/sha opts) (latest-github-sha lib))] + (deps/add-deps {:deps {lib {:git/url url :git/sha sha}}}))))) + (defn run-deps-new [{:keys [opts]}] + (require 'org.corfield.new) (let [{:keys [template] - :or {template "scratch"}} opts - template-fn (requiring-resolve (symbol "org.corfield.new" template))] - (template-fn (dissoc opts :template)) + :or {template "scratch"}} opts] + (when-not (built-in-template? template) + (add-template-deps template opts)) + (System/setProperty "java.class.path" (cp/get-classpath)) + ((resolve 'org.corfield.new/create) opts) nil)) (defn print-help [_] diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index ba53e88..be3f759 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -4,15 +4,13 @@ (require '[babashka.classpath :as cp] '[babashka.cli :as cli] '[babashka.curl :as curl] + '[babashka.deps :as deps] '[babashka.fs :as fs] '[borkdude.rewrite-edn :as r] '[cheshire.core :as cheshire] '[clojure.edn :as edn] '[clojure.string :as str]) -;; deps-new reads classpath from property -(System/setProperty "java.class.path" (cp/get-classpath)) - (def spec {:lib {:desc "Fully qualified library name."} :version {:desc "Optional. When not provided, picks newest version from Clojars or Maven Central."} :sha {:desc "When provided, assumes lib refers to Github repo."} @@ -364,6 +362,11 @@ :target-dir :overwrite + ; template deps overrides + :local/root + :git/url + :git/sha + ; optional overrides :artifact/id :description @@ -381,11 +384,29 @@ :user :version]) +(defn- built-in-template? [template] + (contains? (set (map name (keys (ns-publics 'org.corfield.new)))) template)) + +(defn- github-repo-url [lib] + (str "https://github.com/" (clean-github-lib lib))) + +(defn- add-template-deps [template opts] + (let [lib (edn/read-string template) + local-root (:local/root opts)] + (if local-root + (deps/add-deps {:deps {lib {:local/root local-root}}}) + (let [url (or (:git/url opts) (github-repo-url lib)) + sha (or (:git/sha opts) (latest-github-sha lib))] + (deps/add-deps {:deps {lib {:git/url url :git/sha sha}}}))))) + (defn run-deps-new [{:keys [opts]}] + (require 'org.corfield.new) (let [{:keys [template] - :or {template "scratch"}} opts - template-fn (requiring-resolve (symbol "org.corfield.new" template))] - (template-fn (dissoc opts :template)) + :or {template "scratch"}} opts] + (when-not (built-in-template? template) + (add-template-deps template opts)) + (System/setProperty "java.class.path" (cp/get-classpath)) + ((resolve 'org.corfield.new/create) opts) nil)) (defn print-help [_] From c3ad5ba629a68cf7b030072ed1f143bf2f6b4b9b Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sat, 23 Jul 2022 05:58:56 -0700 Subject: [PATCH 02/25] Add tests --- test-resources/new/my-kit/deps.edn | 2 ++ test-resources/new/my-kit/src/scratch.clj | 12 ++++++++++++ test-resources/new/my-scratch/deps.edn | 2 ++ test-resources/new/my-scratch/src/scratch.clj | 12 ++++++++++++ tests.clj | 18 ++++++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 test-resources/new/my-kit/deps.edn create mode 100644 test-resources/new/my-kit/src/scratch.clj create mode 100644 test-resources/new/my-scratch/deps.edn create mode 100644 test-resources/new/my-scratch/src/scratch.clj diff --git a/test-resources/new/my-kit/deps.edn b/test-resources/new/my-kit/deps.edn new file mode 100644 index 0000000..023cd41 --- /dev/null +++ b/test-resources/new/my-kit/deps.edn @@ -0,0 +1,2 @@ +{:paths ["src"] + :deps {}} diff --git a/test-resources/new/my-kit/src/scratch.clj b/test-resources/new/my-kit/src/scratch.clj new file mode 100644 index 0000000..7150e9f --- /dev/null +++ b/test-resources/new/my-kit/src/scratch.clj @@ -0,0 +1,12 @@ +(ns scratch + "FIXME: my new io.github.rads/kit project.") + +(defn exec + "Invoke me with clojure -X scratch/exec" + [opts] + (println "exec with" opts)) + +(defn -main + "Invoke me with clojure -M -m scratch" + [& args] + (println "-main with" args)) diff --git a/test-resources/new/my-scratch/deps.edn b/test-resources/new/my-scratch/deps.edn new file mode 100644 index 0000000..023cd41 --- /dev/null +++ b/test-resources/new/my-scratch/deps.edn @@ -0,0 +1,2 @@ +{:paths ["src"] + :deps {}} diff --git a/test-resources/new/my-scratch/src/scratch.clj b/test-resources/new/my-scratch/src/scratch.clj new file mode 100644 index 0000000..29b30c8 --- /dev/null +++ b/test-resources/new/my-scratch/src/scratch.clj @@ -0,0 +1,12 @@ +(ns scratch + "FIXME: my new org.corfield.new/scratch project.") + +(defn exec + "Invoke me with clojure -X scratch/exec" + [opts] + (println "exec with" opts)) + +(defn -main + "Invoke me with clojure -M -m scratch" + [& args] + (println "-main with" args)) diff --git a/tests.clj b/tests.clj index d1a0e0c..13585bc 100644 --- a/tests.clj +++ b/tests.clj @@ -82,5 +82,23 @@ (is (thrown-with-msg? Exception #"nonExistentLicense" (run-license out-file "add" "nonExistentLicense")))))) +(deftest new-scratch-test + (let [target-dir (str (fs/temp-dir) "/my-scratch")] + (spit (test-file "deps.edn") "{}") + (neil (str "new scratch my-scratch :overwrite true :target-dir " target-dir)) + (is (= (slurp (fs/file "test-resources/new/my-scratch/src/scratch.clj")) + (slurp (fs/file (str target-dir "/src/scratch.clj"))))) + (is (= (slurp (fs/file "test-resources/new/my-scratch/deps.edn")) + (slurp (fs/file (str target-dir "/deps.edn"))))))) + +(deftest new-remote-test + (let [target-dir (str (fs/temp-dir) "/my-kit")] + (spit (test-file "deps.edn") "{}") + (neil (str "new io.github.rads/kit my-kit :overwrite true :target-dir " target-dir)) + (is (= (slurp (fs/file "test-resources/new/my-kit/src/scratch.clj")) + (slurp (fs/file (str target-dir "/src/scratch.clj"))))) + (is (= (slurp (fs/file "test-resources/new/my-kit/deps.edn")) + (slurp (fs/file (str target-dir "/deps.edn"))))))) + (when (= *file* (System/getProperty "babashka.file")) (t/run-tests *ns*)) From 88295d7b9ae2e0ee3be3d56523ec5aa833f6873b Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sat, 23 Jul 2022 07:26:22 -0700 Subject: [PATCH 03/25] Add :dry-run option --- neil | 37 +++++++++++++++++++++++++++---------- src/babashka/neil.clj | 37 +++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/neil b/neil index 0b48275..e4b021a 100755 --- a/neil +++ b/neil @@ -377,6 +377,7 @@ :name :target-dir :overwrite + :dry-run ; template deps overrides :local/root @@ -406,24 +407,40 @@ (defn- github-repo-url [lib] (str "https://github.com/" (clean-github-lib lib))) -(defn- add-template-deps [template opts] +(defn- template-libs [template opts] (let [lib (edn/read-string template) local-root (:local/root opts)] (if local-root - (deps/add-deps {:deps {lib {:local/root local-root}}}) + {lib {:local/root local-root}} (let [url (or (:git/url opts) (github-repo-url lib)) sha (or (:git/sha opts) (latest-github-sha lib))] - (deps/add-deps {:deps {lib {:git/url url :git/sha sha}}}))))) + {lib {:git/url url :git/sha sha}})))) + +(defn- set-class-path-property [] + (System/setProperty "java.class.path" (cp/get-classpath))) + +(defn- deps-new-plan [cli-opts] + (let [create-opts (merge {:template "scratch"} + (dissoc cli-opts :dry-run :deps-file)) + template-deps (when-not (built-in-template? (:template create-opts)) + (template-libs (:template create-opts) cli-opts))] + {:template-deps template-deps + :create-opts create-opts})) + +(defn- deps-new-create [create-opts] + ((resolve 'org.corfield.new/create) create-opts)) (defn run-deps-new [{:keys [opts]}] (require 'org.corfield.new) - (let [{:keys [template] - :or {template "scratch"}} opts] - (when-not (built-in-template? template) - (add-template-deps template opts)) - (System/setProperty "java.class.path" (cp/get-classpath)) - ((resolve 'org.corfield.new/create) opts) - nil)) + (let [plan (deps-new-plan opts) + {:keys [template-deps create-opts]} plan] + (if (:dry-run opts) + plan + (do + (when template-deps (deps/add-deps {:deps template-deps})) + (set-class-path-property) + (deps-new-create create-opts) + nil)))) (defn print-help [_] (println (str/trim " diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index be3f759..2968099 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -361,6 +361,7 @@ :name :target-dir :overwrite + :dry-run ; template deps overrides :local/root @@ -390,24 +391,40 @@ (defn- github-repo-url [lib] (str "https://github.com/" (clean-github-lib lib))) -(defn- add-template-deps [template opts] +(defn- template-libs [template opts] (let [lib (edn/read-string template) local-root (:local/root opts)] (if local-root - (deps/add-deps {:deps {lib {:local/root local-root}}}) + {lib {:local/root local-root}} (let [url (or (:git/url opts) (github-repo-url lib)) sha (or (:git/sha opts) (latest-github-sha lib))] - (deps/add-deps {:deps {lib {:git/url url :git/sha sha}}}))))) + {lib {:git/url url :git/sha sha}})))) + +(defn- set-class-path-property [] + (System/setProperty "java.class.path" (cp/get-classpath))) + +(defn- deps-new-plan [cli-opts] + (let [create-opts (merge {:template "scratch"} + (dissoc cli-opts :dry-run :deps-file)) + template-deps (when-not (built-in-template? (:template create-opts)) + (template-libs (:template create-opts) cli-opts))] + {:template-deps template-deps + :create-opts create-opts})) + +(defn- deps-new-create [create-opts] + ((resolve 'org.corfield.new/create) create-opts)) (defn run-deps-new [{:keys [opts]}] (require 'org.corfield.new) - (let [{:keys [template] - :or {template "scratch"}} opts] - (when-not (built-in-template? template) - (add-template-deps template opts)) - (System/setProperty "java.class.path" (cp/get-classpath)) - ((resolve 'org.corfield.new/create) opts) - nil)) + (let [plan (deps-new-plan opts) + {:keys [template-deps create-opts]} plan] + (if (:dry-run opts) + plan + (do + (when template-deps (deps/add-deps {:deps template-deps})) + (set-class-path-property) + (deps-new-create create-opts) + nil)))) (defn print-help [_] (println (str/trim " From 3d20a9899e142b5b6ee3ad382352fc9273ce4993 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sat, 23 Jul 2022 07:43:46 -0700 Subject: [PATCH 04/25] Update tests --- test-resources/new/my-scratch/deps.edn | 2 -- test-resources/new/my-scratch/src/scratch.clj | 12 --------- tests.clj | 25 ++++++++++++++----- 3 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 test-resources/new/my-scratch/deps.edn delete mode 100644 test-resources/new/my-scratch/src/scratch.clj diff --git a/test-resources/new/my-scratch/deps.edn b/test-resources/new/my-scratch/deps.edn deleted file mode 100644 index 023cd41..0000000 --- a/test-resources/new/my-scratch/deps.edn +++ /dev/null @@ -1,2 +0,0 @@ -{:paths ["src"] - :deps {}} diff --git a/test-resources/new/my-scratch/src/scratch.clj b/test-resources/new/my-scratch/src/scratch.clj deleted file mode 100644 index 29b30c8..0000000 --- a/test-resources/new/my-scratch/src/scratch.clj +++ /dev/null @@ -1,12 +0,0 @@ -(ns scratch - "FIXME: my new org.corfield.new/scratch project.") - -(defn exec - "Invoke me with clojure -X scratch/exec" - [opts] - (println "exec with" opts)) - -(defn -main - "Invoke me with clojure -M -m scratch" - [& args] - (println "-main with" args)) diff --git a/tests.clj b/tests.clj index 13585bc..e110974 100644 --- a/tests.clj +++ b/tests.clj @@ -82,19 +82,32 @@ (is (thrown-with-msg? Exception #"nonExistentLicense" (run-license out-file "add" "nonExistentLicense")))))) +(defn run-new-command [& args] + (-> @(process (concat ["./neil" "new"] args) {:out :string}) + :out + edn/read-string)) + (deftest new-scratch-test (let [target-dir (str (fs/temp-dir) "/my-scratch")] (spit (test-file "deps.edn") "{}") - (neil (str "new scratch my-scratch :overwrite true :target-dir " target-dir)) - (is (= (slurp (fs/file "test-resources/new/my-scratch/src/scratch.clj")) - (slurp (fs/file (str target-dir "/src/scratch.clj"))))) - (is (= (slurp (fs/file "test-resources/new/my-scratch/deps.edn")) - (slurp (fs/file (str target-dir "/deps.edn"))))))) + (let [edn (run-new-command "scratch" "my-scratch" + ":target-dir" target-dir + ":dry-run" "true" + ":overwrite" "true")] + (is (= {:template-deps nil + :create-opts {:template "scratch" + :overwrite true + :target-dir target-dir + :name "my-scratch"}} + edn))))) (deftest new-remote-test (let [target-dir (str (fs/temp-dir) "/my-kit")] + (fs/delete-tree target-dir) (spit (test-file "deps.edn") "{}") - (neil (str "new io.github.rads/kit my-kit :overwrite true :target-dir " target-dir)) + (run-new-command "io.github.rads/kit" "my-kit" + ":target-dir" target-dir + ":overwrite" "true") (is (= (slurp (fs/file "test-resources/new/my-kit/src/scratch.clj")) (slurp (fs/file (str target-dir "/src/scratch.clj"))))) (is (= (slurp (fs/file "test-resources/new/my-kit/deps.edn")) From d44b50eeb1249990a36de179b68d8aa8664fed64 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sat, 23 Jul 2022 08:13:22 -0700 Subject: [PATCH 05/25] Add new-overrides-test --- tests.clj | 69 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/tests.clj b/tests.clj index e110974..d8b6ddf 100644 --- a/tests.clj +++ b/tests.clj @@ -101,17 +101,72 @@ :name "my-scratch"}} edn))))) +(deftest new-overrides-test + (spit (test-file "deps.edn") "{}") + (let [edn (run-new-command ":artifact/id" "foo" + ":description" "foo" + ":developer" "foo" + ":dry-run" "true" + ":group/id" "foo" + ":main" "foo" + ":name" "my-scratch" + ":now/date" "foo" + ":now/year" "foo" + ":overwrite" "true" + ":raw-name" "foo" + ":scm/domain" "foo" + ":scm/repo" "foo" + ":scm/user" "foo" + ":target-dir" "foo" + ":template" "scratch" + ":top" "foo" + ":user" "foo" + ":version" "foo")] + (is (= {:template-deps nil + :create-opts {:artifact/id "foo" + :description "foo" + :developer "foo" + :group/id "foo" + :main "foo" + :name "my-scratch" + :now/date "foo" + :now/year "foo" + :overwrite true + :raw-name "foo" + :scm/domain "foo" + :scm/repo "foo" + :scm/user "foo" + :target-dir "foo" + :template "scratch" + :top "foo" + :user "foo" + :version "foo"}} + edn)))) + (deftest new-remote-test (let [target-dir (str (fs/temp-dir) "/my-kit")] (fs/delete-tree target-dir) (spit (test-file "deps.edn") "{}") - (run-new-command "io.github.rads/kit" "my-kit" - ":target-dir" target-dir - ":overwrite" "true") - (is (= (slurp (fs/file "test-resources/new/my-kit/src/scratch.clj")) - (slurp (fs/file (str target-dir "/src/scratch.clj"))))) - (is (= (slurp (fs/file "test-resources/new/my-kit/deps.edn")) - (slurp (fs/file (str target-dir "/deps.edn"))))))) + (let [run #(apply run-new-command + "io.github.rads/kit" "my-kit" + ":target-dir" target-dir + ":overwrite" "true" + %&)] + (testing "dry run" + (is (= {:template-deps {'io.github.rads/kit + {:git/url "https://github.com/rads/kit" + :git/sha "a7169fec2d20fd414bcb194bb40a067cae9a80ac"}} + :create-opts {:template "io.github.rads/kit" + :target-dir target-dir + :overwrite true + :name "my-kit"}} + (run ":dry-run" "true")))) + (testing "template output" + (run ":dry-run" "false") + (is (= (slurp (fs/file "test-resources/new/my-kit/src/scratch.clj")) + (slurp (fs/file (str target-dir "/src/scratch.clj"))))) + (is (= (slurp (fs/file "test-resources/new/my-kit/deps.edn")) + (slurp (fs/file (str target-dir "/deps.edn"))))))))) (when (= *file* (System/getProperty "babashka.file")) (t/run-tests *ns*)) From ed3ec1f8dbba898c91f3a0627306babd941da26a Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sun, 24 Jul 2022 13:22:18 -0700 Subject: [PATCH 06/25] Update tests --- .../new/{my-kit => my-scratch}/deps.edn | 0 .../{my-kit => my-scratch}/src/scratch.clj | 2 +- tests.clj | 24 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) rename test-resources/new/{my-kit => my-scratch}/deps.edn (100%) rename test-resources/new/{my-kit => my-scratch}/src/scratch.clj (75%) diff --git a/test-resources/new/my-kit/deps.edn b/test-resources/new/my-scratch/deps.edn similarity index 100% rename from test-resources/new/my-kit/deps.edn rename to test-resources/new/my-scratch/deps.edn diff --git a/test-resources/new/my-kit/src/scratch.clj b/test-resources/new/my-scratch/src/scratch.clj similarity index 75% rename from test-resources/new/my-kit/src/scratch.clj rename to test-resources/new/my-scratch/src/scratch.clj index 7150e9f..8f80caf 100644 --- a/test-resources/new/my-kit/src/scratch.clj +++ b/test-resources/new/my-scratch/src/scratch.clj @@ -1,5 +1,5 @@ (ns scratch - "FIXME: my new io.github.rads/kit project.") + "FIXME: my new io.github.rads/neil-new-test-template project.") (defn exec "Invoke me with clojure -X scratch/exec" diff --git a/tests.clj b/tests.clj index d8b6ddf..40fcf9d 100644 --- a/tests.clj +++ b/tests.clj @@ -41,11 +41,11 @@ (deftest dep-search-test (is (thrown? java.lang.Exception (run-dep-subcommand "search" "someBougusLibThatDoesntExist"))) (is (not-empty (run-dep-subcommand "search" "hiccups"))) - (is (some #(str/starts-with? % ":lib hiccups/hiccups" ) + (is (some #(str/starts-with? % ":lib hiccups/hiccups") (run-dep-subcommand "search" "hiccups"))) - (is (some #(re-matches #":lib hiccups/hiccups :version \d+(\.\d+)+ :description .*" % ) + (is (some #(re-matches #":lib hiccups/hiccups :version \d+(\.\d+)+ :description .*" %) (run-dep-subcommand "search" "hiccups"))) - (is (some #(re-matches #":lib macchiato/hiccups :version \d+(\.\d+)+ :description .*" % ) + (is (some #(re-matches #":lib macchiato/hiccups :version \d+(\.\d+)+ :description .*" %) (run-dep-subcommand "search" "hiccups"))) ; tests for no NPEs/json parsing exceptions (is (any? (run-dep-subcommand "search" "org.clojure/tools.cli"))) @@ -144,28 +144,28 @@ edn)))) (deftest new-remote-test - (let [target-dir (str (fs/temp-dir) "/my-kit")] + (let [target-dir (str (fs/temp-dir) "/my-scratch")] (fs/delete-tree target-dir) (spit (test-file "deps.edn") "{}") (let [run #(apply run-new-command - "io.github.rads/kit" "my-kit" + "io.github.rads/neil-new-test-template" "my-scratch" ":target-dir" target-dir ":overwrite" "true" %&)] (testing "dry run" - (is (= {:template-deps {'io.github.rads/kit - {:git/url "https://github.com/rads/kit" - :git/sha "a7169fec2d20fd414bcb194bb40a067cae9a80ac"}} - :create-opts {:template "io.github.rads/kit" + (is (= {:template-deps {'io.github.rads/neil-new-test-template + {:git/url "https://github.com/rads/neil-new-test-template" + :git/sha "e7954c34146fcdc4ab54fa4690bec3ceb9247d05"}} + :create-opts {:template "io.github.rads/neil-new-test-template" :target-dir target-dir :overwrite true - :name "my-kit"}} + :name "my-scratch"}} (run ":dry-run" "true")))) (testing "template output" (run ":dry-run" "false") - (is (= (slurp (fs/file "test-resources/new/my-kit/src/scratch.clj")) + (is (= (slurp (fs/file "test-resources/new/my-scratch/src/scratch.clj")) (slurp (fs/file (str target-dir "/src/scratch.clj"))))) - (is (= (slurp (fs/file "test-resources/new/my-kit/deps.edn")) + (is (= (slurp (fs/file "test-resources/new/my-scratch/deps.edn")) (slurp (fs/file (str target-dir "/deps.edn"))))))))) (when (= *file* (System/getProperty "babashka.file")) From 550d00c5f57f6afd565ad3baf6488ff545f23bc3 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sun, 24 Jul 2022 14:52:21 -0700 Subject: [PATCH 07/25] Use requiring-resolve in deps-new-create --- neil | 2 +- src/babashka/neil.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/neil b/neil index e4b021a..d8f187c 100755 --- a/neil +++ b/neil @@ -428,7 +428,7 @@ :create-opts create-opts})) (defn- deps-new-create [create-opts] - ((resolve 'org.corfield.new/create) create-opts)) + ((requiring-resolve 'org.corfield.new/create) create-opts)) (defn run-deps-new [{:keys [opts]}] (require 'org.corfield.new) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 2968099..4a0d184 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -412,7 +412,7 @@ :create-opts create-opts})) (defn- deps-new-create [create-opts] - ((resolve 'org.corfield.new/create) create-opts)) + ((requiring-resolve 'org.corfield.new/create) create-opts)) (defn run-deps-new [{:keys [opts]}] (require 'org.corfield.new) From 4a76ad3c1f77b5cd7522df039b940e420d149798 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sun, 24 Jul 2022 14:55:25 -0700 Subject: [PATCH 08/25] Clean up opts The new-scratch-test already covers extra opts (:overwrite) --- neil | 32 +------------------------------- src/babashka/neil.clj | 36 +++--------------------------------- tests.clj | 42 ------------------------------------------ 3 files changed, 4 insertions(+), 106 deletions(-) diff --git a/neil b/neil index d8f187c..c3449ac 100755 --- a/neil +++ b/neil @@ -371,36 +371,6 @@ :version (:version search-result) :description (pr-str (:description search-result)))))) -(def deps-new-opts - [; main opts - :template - :name - :target-dir - :overwrite - :dry-run - - ; template deps overrides - :local/root - :git/url - :git/sha - - ; optional overrides - :artifact/id - :description - :developer - :group/id - :main - :name - :now/date - :now/year - :raw-name - :scm/domain - :scm/user - :scm/repo - :top - :user - :version]) - (defn- built-in-template? [template] (contains? (set (map name (keys (ns-publics 'org.corfield.new)))) template)) @@ -541,7 +511,7 @@ license {:cmds ["license" "list"] :fn license-search :cmds-opts [:search-term]} {:cmds ["license" "search"] :fn license-search :cmds-opts [:search-term]} {:cmds ["license" "add"] :fn add-license :cmds-opts [:license]} - {:cmds ["new"] :fn run-deps-new :cmds-opts deps-new-opts} + {:cmds ["new"] :fn run-deps-new :cmds-opts [:template :name :target-dir]} {:cmds ["version"] :fn print-version} {:cmds ["help"] :fn print-help} {:cmds [] :fn (fn [{:keys [opts] :as m}] diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 4a0d184..38655be 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -24,8 +24,8 @@ :deps-file {:ref "" :desc "Add to instead of deps.edn." :default "deps.edn"} - :limit {:coerce :long} - }) + :limit {:coerce :long}}) + (import java.net.URLEncoder) @@ -355,36 +355,6 @@ :version (:version search-result) :description (pr-str (:description search-result)))))) -(def deps-new-opts - [; main opts - :template - :name - :target-dir - :overwrite - :dry-run - - ; template deps overrides - :local/root - :git/url - :git/sha - - ; optional overrides - :artifact/id - :description - :developer - :group/id - :main - :name - :now/date - :now/year - :raw-name - :scm/domain - :scm/user - :scm/repo - :top - :user - :version]) - (defn- built-in-template? [template] (contains? (set (map name (keys (ns-publics 'org.corfield.new)))) template)) @@ -525,7 +495,7 @@ license {:cmds ["license" "list"] :fn license-search :cmds-opts [:search-term]} {:cmds ["license" "search"] :fn license-search :cmds-opts [:search-term]} {:cmds ["license" "add"] :fn add-license :cmds-opts [:license]} - {:cmds ["new"] :fn run-deps-new :cmds-opts deps-new-opts} + {:cmds ["new"] :fn run-deps-new :cmds-opts [:template :name :target-dir]} {:cmds ["version"] :fn print-version} {:cmds ["help"] :fn print-help} {:cmds [] :fn (fn [{:keys [opts] :as m}] diff --git a/tests.clj b/tests.clj index 40fcf9d..04f38fd 100644 --- a/tests.clj +++ b/tests.clj @@ -101,48 +101,6 @@ :name "my-scratch"}} edn))))) -(deftest new-overrides-test - (spit (test-file "deps.edn") "{}") - (let [edn (run-new-command ":artifact/id" "foo" - ":description" "foo" - ":developer" "foo" - ":dry-run" "true" - ":group/id" "foo" - ":main" "foo" - ":name" "my-scratch" - ":now/date" "foo" - ":now/year" "foo" - ":overwrite" "true" - ":raw-name" "foo" - ":scm/domain" "foo" - ":scm/repo" "foo" - ":scm/user" "foo" - ":target-dir" "foo" - ":template" "scratch" - ":top" "foo" - ":user" "foo" - ":version" "foo")] - (is (= {:template-deps nil - :create-opts {:artifact/id "foo" - :description "foo" - :developer "foo" - :group/id "foo" - :main "foo" - :name "my-scratch" - :now/date "foo" - :now/year "foo" - :overwrite true - :raw-name "foo" - :scm/domain "foo" - :scm/repo "foo" - :scm/user "foo" - :target-dir "foo" - :template "scratch" - :top "foo" - :user "foo" - :version "foo"}} - edn)))) - (deftest new-remote-test (let [target-dir (str (fs/temp-dir) "/my-scratch")] (fs/delete-tree target-dir) From 73bd5097ed71d5872eb813b813daefb3aa51bf51 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sun, 24 Jul 2022 15:25:38 -0700 Subject: [PATCH 09/25] Restrict lib options to only valid combinations --- neil | 47 ++++++++++++++++++++++++++++++++++--------- src/babashka/neil.clj | 43 ++++++++++++++++++++++++++++++++------- 2 files changed, 74 insertions(+), 16 deletions(-) diff --git a/neil b/neil index c3449ac..cc87bea 100755 --- a/neil +++ b/neil @@ -40,8 +40,8 @@ :deps-file {:ref "" :desc "Add to instead of deps.edn." :default "deps.edn"} - :limit {:coerce :long} - }) + :limit {:coerce :long}}) + (import java.net.URLEncoder) @@ -377,14 +377,43 @@ (defn- github-repo-url [lib] (str "https://github.com/" (clean-github-lib lib))) +(def valid-lib-opts + #{#{} + #{:local/root} + #{:git/sha} + #{:git/tag} + #{:git/url} + #{:git/url :git/sha} + #{:git/url :git/tag}}) + +(defn invalid-lib-opts-message [lib-opts] + (str "Requires one of the following combinations of lib options:\n" + (pr-str valid-lib-opts) "\n\n" + "Provided:\n" + (pr-str lib-opts))) + (defn- template-libs [template opts] - (let [lib (edn/read-string template) - local-root (:local/root opts)] - (if local-root - {lib {:local/root local-root}} - (let [url (or (:git/url opts) (github-repo-url lib)) - sha (or (:git/sha opts) (latest-github-sha lib))] - {lib {:git/url url :git/sha sha}})))) + (let [lib-opts (set (keys (select-keys opts (into #{} cat valid-lib-opts)))) + lib-sym (edn/read-string template)] + (case lib-opts + (#{:local/root}) + {lib-sym {:local/root (:local/root opts)}} + + (#{} + #{:git/sha} + #{:git/url} + #{:git/url :git/sha}) + (let [url (or (:git/url opts) (github-repo-url lib-sym)) + sha (or (:git/sha opts) (latest-github-sha lib-sym))] + {lib-sym {:git/url url :git/sha sha}}) + + (#{:git/tag} + #{:git/url :git/tag}) + (let [url (or (:git/url opts) (github-repo-url lib-sym)) + tag (or (:git/tag opts) (latest-github-tag lib-sym))] + {lib-sym {:git/url url :git/tag tag}}) + + (throw (ex-info (invalid-lib-opts-message lib-opts) {}))))) (defn- set-class-path-property [] (System/setProperty "java.class.path" (cp/get-classpath))) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 38655be..fee6bbf 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -361,14 +361,43 @@ (defn- github-repo-url [lib] (str "https://github.com/" (clean-github-lib lib))) +(def valid-lib-opts + #{#{} + #{:local/root} + #{:git/sha} + #{:git/tag} + #{:git/url} + #{:git/url :git/sha} + #{:git/url :git/tag}}) + +(defn invalid-lib-opts-message [lib-opts] + (str "Requires one of the following combinations of lib options:\n" + (pr-str valid-lib-opts) "\n\n" + "Provided:\n" + (pr-str lib-opts))) + (defn- template-libs [template opts] - (let [lib (edn/read-string template) - local-root (:local/root opts)] - (if local-root - {lib {:local/root local-root}} - (let [url (or (:git/url opts) (github-repo-url lib)) - sha (or (:git/sha opts) (latest-github-sha lib))] - {lib {:git/url url :git/sha sha}})))) + (let [lib-opts (set (keys (select-keys opts (into #{} cat valid-lib-opts)))) + lib-sym (edn/read-string template)] + (case lib-opts + (#{:local/root}) + {lib-sym {:local/root (:local/root opts)}} + + (#{} + #{:git/sha} + #{:git/url} + #{:git/url :git/sha}) + (let [url (or (:git/url opts) (github-repo-url lib-sym)) + sha (or (:git/sha opts) (latest-github-sha lib-sym))] + {lib-sym {:git/url url :git/sha sha}}) + + (#{:git/tag} + #{:git/url :git/tag}) + (let [url (or (:git/url opts) (github-repo-url lib-sym)) + tag (or (:git/tag opts) (latest-github-tag lib-sym))] + {lib-sym {:git/url url :git/tag tag}}) + + (throw (ex-info (invalid-lib-opts-message lib-opts) {}))))) (defn- set-class-path-property [] (System/setProperty "java.class.path" (cp/get-classpath))) From bc92e9d127250369244d7620503a1b132e7f80b8 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sun, 24 Jul 2022 15:31:40 -0700 Subject: [PATCH 10/25] Use :git/tag instead of :git/sha by default when omitted --- neil | 8 ++++---- src/babashka/neil.clj | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/neil b/neil index cc87bea..27f2f6e 100755 --- a/neil +++ b/neil @@ -399,15 +399,15 @@ (#{:local/root}) {lib-sym {:local/root (:local/root opts)}} - (#{} - #{:git/sha} - #{:git/url} + (#{:git/sha} #{:git/url :git/sha}) (let [url (or (:git/url opts) (github-repo-url lib-sym)) sha (or (:git/sha opts) (latest-github-sha lib-sym))] {lib-sym {:git/url url :git/sha sha}}) - (#{:git/tag} + (#{} + #{:git/tag} + #{:git/url} #{:git/url :git/tag}) (let [url (or (:git/url opts) (github-repo-url lib-sym)) tag (or (:git/tag opts) (latest-github-tag lib-sym))] diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index fee6bbf..1917d73 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -383,15 +383,15 @@ (#{:local/root}) {lib-sym {:local/root (:local/root opts)}} - (#{} - #{:git/sha} - #{:git/url} + (#{:git/sha} #{:git/url :git/sha}) (let [url (or (:git/url opts) (github-repo-url lib-sym)) sha (or (:git/sha opts) (latest-github-sha lib-sym))] {lib-sym {:git/url url :git/sha sha}}) - (#{:git/tag} + (#{} + #{:git/tag} + #{:git/url} #{:git/url :git/tag}) (let [url (or (:git/url opts) (github-repo-url lib-sym)) tag (or (:git/tag opts) (latest-github-tag lib-sym))] From 249e2d4f258f20368ed4def8c275c2c043bf65e0 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Sun, 24 Jul 2022 16:04:00 -0700 Subject: [PATCH 11/25] Improve template-libs logic and update tests --- neil | 49 ++++++++++++++++++++++++++++++------------- src/babashka/neil.clj | 49 ++++++++++++++++++++++++++++++------------- tests.clj | 1 + 3 files changed, 71 insertions(+), 28 deletions(-) diff --git a/neil b/neil index 27f2f6e..45a5d36 100755 --- a/neil +++ b/neil @@ -111,6 +111,11 @@ (namespace lib) (name lib) branch)) :sha))) +(defn list-tags [lib] + (let [lib (clean-github-lib lib)] + (curl-get-json (format "https://api.github.com/repos/%s/%s/tags" + (namespace lib) (name lib))))) + (defn latest-github-tag [lib] (let [lib (clean-github-lib lib)] (first @@ -378,13 +383,18 @@ (str "https://github.com/" (clean-github-lib lib))) (def valid-lib-opts - #{#{} - #{:local/root} - #{:git/sha} - #{:git/tag} + #{#{:local/root} + + #{} #{:git/url} + + #{:git/tag} + #{:git/url :git/tag} + + #{:git/sha} #{:git/url :git/sha} - #{:git/url :git/tag}}) + + #{:git/url :git/tag :git/sha}}) (defn invalid-lib-opts-message [lib-opts] (str "Requires one of the following combinations of lib options:\n" @@ -397,21 +407,32 @@ lib-sym (edn/read-string template)] (case lib-opts (#{:local/root}) - {lib-sym {:local/root (:local/root opts)}} + {lib-sym (select-keys opts [:local/root])} + + (#{} + #{:git/url}) + (let [url (or (:git/url opts) (github-repo-url lib-sym)) + {:keys [name commit]} (latest-github-tag lib-sym)] + {lib-sym {:git/url url :git/tag name :git/sha (:sha commit)}}) + + (#{:git/tag} + #{:git/url :git/tag}) + (let [url (or (:git/url opts) (github-repo-url lib-sym)) + tag (:git/tag opts) + commit (->> (list-tags lib-sym) + (filter #(= (:name %) tag)) + first + :commit)] + {lib-sym {:git/url url :git/tag tag :git/sha (:sha commit)}}) (#{:git/sha} #{:git/url :git/sha}) (let [url (or (:git/url opts) (github-repo-url lib-sym)) - sha (or (:git/sha opts) (latest-github-sha lib-sym))] + sha (:git/sha opts)] {lib-sym {:git/url url :git/sha sha}}) - (#{} - #{:git/tag} - #{:git/url} - #{:git/url :git/tag}) - (let [url (or (:git/url opts) (github-repo-url lib-sym)) - tag (or (:git/tag opts) (latest-github-tag lib-sym))] - {lib-sym {:git/url url :git/tag tag}}) + #{:git/url :git/tag :git/sha} + {lib-sym (select-keys opts [:git/url :git/tag :git/sha])} (throw (ex-info (invalid-lib-opts-message lib-opts) {}))))) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 1917d73..a424607 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -95,6 +95,11 @@ (namespace lib) (name lib) branch)) :sha))) +(defn list-tags [lib] + (let [lib (clean-github-lib lib)] + (curl-get-json (format "https://api.github.com/repos/%s/%s/tags" + (namespace lib) (name lib))))) + (defn latest-github-tag [lib] (let [lib (clean-github-lib lib)] (first @@ -362,13 +367,18 @@ (str "https://github.com/" (clean-github-lib lib))) (def valid-lib-opts - #{#{} - #{:local/root} - #{:git/sha} - #{:git/tag} + #{#{:local/root} + + #{} #{:git/url} + + #{:git/tag} + #{:git/url :git/tag} + + #{:git/sha} #{:git/url :git/sha} - #{:git/url :git/tag}}) + + #{:git/url :git/tag :git/sha}}) (defn invalid-lib-opts-message [lib-opts] (str "Requires one of the following combinations of lib options:\n" @@ -381,21 +391,32 @@ lib-sym (edn/read-string template)] (case lib-opts (#{:local/root}) - {lib-sym {:local/root (:local/root opts)}} + {lib-sym (select-keys opts [:local/root])} + + (#{} + #{:git/url}) + (let [url (or (:git/url opts) (github-repo-url lib-sym)) + {:keys [name commit]} (latest-github-tag lib-sym)] + {lib-sym {:git/url url :git/tag name :git/sha (:sha commit)}}) + + (#{:git/tag} + #{:git/url :git/tag}) + (let [url (or (:git/url opts) (github-repo-url lib-sym)) + tag (:git/tag opts) + commit (->> (list-tags lib-sym) + (filter #(= (:name %) tag)) + first + :commit)] + {lib-sym {:git/url url :git/tag tag :git/sha (:sha commit)}}) (#{:git/sha} #{:git/url :git/sha}) (let [url (or (:git/url opts) (github-repo-url lib-sym)) - sha (or (:git/sha opts) (latest-github-sha lib-sym))] + sha (:git/sha opts)] {lib-sym {:git/url url :git/sha sha}}) - (#{} - #{:git/tag} - #{:git/url} - #{:git/url :git/tag}) - (let [url (or (:git/url opts) (github-repo-url lib-sym)) - tag (or (:git/tag opts) (latest-github-tag lib-sym))] - {lib-sym {:git/url url :git/tag tag}}) + #{:git/url :git/tag :git/sha} + {lib-sym (select-keys opts [:git/url :git/tag :git/sha])} (throw (ex-info (invalid-lib-opts-message lib-opts) {}))))) diff --git a/tests.clj b/tests.clj index 04f38fd..b764126 100644 --- a/tests.clj +++ b/tests.clj @@ -113,6 +113,7 @@ (testing "dry run" (is (= {:template-deps {'io.github.rads/neil-new-test-template {:git/url "https://github.com/rads/neil-new-test-template" + :git/tag "1.0.0" :git/sha "e7954c34146fcdc4ab54fa4690bec3ceb9247d05"}} :create-opts {:template "io.github.rads/neil-new-test-template" :target-dir target-dir From a6ee5862ad6a4112beae8e9f4cdfae41154da41f Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Wed, 27 Jul 2022 18:30:44 -0700 Subject: [PATCH 12/25] Clean up template-deps function and add docstrings --- neil | 152 +++++++++++++++++++++++++----------------- src/babashka/neil.clj | 152 +++++++++++++++++++++++++----------------- 2 files changed, 184 insertions(+), 120 deletions(-) diff --git a/neil b/neil index 45a5d36..276aab9 100755 --- a/neil +++ b/neil @@ -376,81 +376,113 @@ :version (:version search-result) :description (pr-str (:description search-result)))))) -(defn- built-in-template? [template] +(defn- built-in-template? + "Returns true if the template name maps to a function in org.corfield.new." + [template] (contains? (set (map name (keys (ns-publics 'org.corfield.new)))) template)) (defn- github-repo-url [lib] (str "https://github.com/" (clean-github-lib lib))) +(def lib-opts->template-deps-fn + "A map to define valid CLI options for deps-new template deps. + + - Each key is a sequence of valid combinations of CLI opts. + - Each value is a function which returns a tools.deps lib map." + {[#{:local/root}] + (fn [lib-sym lib-opts] + {lib-sym (select-keys lib-opts [:local/root])}) + + [#{} #{:git/url}] + (fn [lib-sym lib-opts] + (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + {:keys [name commit]} (latest-github-tag lib-sym)] + {lib-sym {:git/url url :git/tag name :git/sha (:sha commit)}})) + + [#{:git/tag} #{:git/url :git/tag}] + (fn [lib-sym lib-opts] + (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + tag (:git/tag lib-opts) + commit (->> (list-tags lib-sym) + (filter #(= (:name %) tag)) + first + :commit)] + {lib-sym {:git/url url :git/tag tag :git/sha (:sha commit)}})) + + [#{:git/sha} #{:git/url :git/sha}] + (fn [lib-sym lib-opts] + (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + sha (:git/sha lib-opts)] + {lib-sym {:git/url url :git/sha sha}})) + + [#{:git/url :git/tag :git/sha}] + (fn [lib-sym lib-opts] + {lib-sym (select-keys lib-opts [:git/url :git/tag :git/sha])})}) + (def valid-lib-opts - #{#{:local/root} - - #{} - #{:git/url} - - #{:git/tag} - #{:git/url :git/tag} - - #{:git/sha} - #{:git/url :git/sha} - - #{:git/url :git/tag :git/sha}}) - -(defn invalid-lib-opts-message [lib-opts] - (str "Requires one of the following combinations of lib options:\n" - (pr-str valid-lib-opts) "\n\n" - "Provided:\n" - (pr-str lib-opts))) - -(defn- template-libs [template opts] - (let [lib-opts (set (keys (select-keys opts (into #{} cat valid-lib-opts)))) - lib-sym (edn/read-string template)] - (case lib-opts - (#{:local/root}) - {lib-sym (select-keys opts [:local/root])} - - (#{} - #{:git/url}) - (let [url (or (:git/url opts) (github-repo-url lib-sym)) - {:keys [name commit]} (latest-github-tag lib-sym)] - {lib-sym {:git/url url :git/tag name :git/sha (:sha commit)}}) - - (#{:git/tag} - #{:git/url :git/tag}) - (let [url (or (:git/url opts) (github-repo-url lib-sym)) - tag (:git/tag opts) - commit (->> (list-tags lib-sym) - (filter #(= (:name %) tag)) - first - :commit)] - {lib-sym {:git/url url :git/tag tag :git/sha (:sha commit)}}) - - (#{:git/sha} - #{:git/url :git/sha}) - (let [url (or (:git/url opts) (github-repo-url lib-sym)) - sha (:git/sha opts)] - {lib-sym {:git/url url :git/sha sha}}) - - #{:git/url :git/tag :git/sha} - {lib-sym (select-keys opts [:git/url :git/tag :git/sha])} - - (throw (ex-info (invalid-lib-opts-message lib-opts) {}))))) - -(defn- set-class-path-property [] + "The set of all valid combinations of deps-new template deps opts." + (into #{} cat (keys lib-opts->template-deps-fn))) + +(defn- deps-new-cli-opts->lib-opts + "Returns parsed deps-new template deps opts from raw CLI opts." + [cli-opts] + (select-keys cli-opts (into #{} cat valid-lib-opts))) + +(defn- invalid-lib-opts-error [provided-lib-opts] + (ex-info (str "Provided invalid combination of CLI options for deps-new " + "template deps.") + {:provided-opts (set (keys provided-lib-opts)) + :valid-combinations valid-lib-opts})) + +(defn- find-template-deps-fn + "Returns a template-deps-fn given lib-opts parsed from raw CLI opts." + [lib-opts] + (some (fn [[k v]] (and (contains? (set k) (set (keys lib-opts))) v)) + lib-opts->template-deps-fn)) + +(defn- template-deps + "Returns a tools.deps lib map for the given CLI opts." + [template cli-opts] + (let [lib-opts (deps-new-cli-opts->lib-opts cli-opts) + lib-sym (edn/read-string template) + template-deps-fn (find-template-deps-fn lib-opts)] + (if-not template-deps-fn + (throw (invalid-lib-opts-error lib-opts)) + (template-deps-fn lib-sym lib-opts)))) + +(defn- set-class-path-property + "Sets the java.class.path property to the current classpath. + + This needs to be called before running org.corfield.new/create." + [] (System/setProperty "java.class.path" (cp/get-classpath))) -(defn- deps-new-plan [cli-opts] +(defn- deps-new-plan + "Returns a plan for calling org.corfield.new/create. + + :template-deps - These deps will be added with babashka.deps/add-deps before + calling the create function. + + :create-opts - This map contains the options that will be passed to the + create function." + [cli-opts] (let [create-opts (merge {:template "scratch"} (dissoc cli-opts :dry-run :deps-file)) - template-deps (when-not (built-in-template? (:template create-opts)) - (template-libs (:template create-opts) cli-opts))] - {:template-deps template-deps + tpl-deps (when-not (built-in-template? (:template create-opts)) + (template-deps (:template create-opts) cli-opts))] + {:template-deps tpl-deps :create-opts create-opts})) (defn- deps-new-create [create-opts] ((requiring-resolve 'org.corfield.new/create) create-opts)) -(defn run-deps-new [{:keys [opts]}] +(defn run-deps-new + "Runs org.corfield.new/create using the provided CLI options. + + To support the dry run feature, side-effects should be described in the plan + provided by deps-new-plan. This function's job is to execute side-effects + using the plan to provide repeatability." + [{:keys [opts]}] (require 'org.corfield.new) (let [plan (deps-new-plan opts) {:keys [template-deps create-opts]} plan] diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index a424607..09dd35c 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -360,81 +360,113 @@ :version (:version search-result) :description (pr-str (:description search-result)))))) -(defn- built-in-template? [template] +(defn- built-in-template? + "Returns true if the template name maps to a function in org.corfield.new." + [template] (contains? (set (map name (keys (ns-publics 'org.corfield.new)))) template)) (defn- github-repo-url [lib] (str "https://github.com/" (clean-github-lib lib))) +(def lib-opts->template-deps-fn + "A map to define valid CLI options for deps-new template deps. + + - Each key is a sequence of valid combinations of CLI opts. + - Each value is a function which returns a tools.deps lib map." + {[#{:local/root}] + (fn [lib-sym lib-opts] + {lib-sym (select-keys lib-opts [:local/root])}) + + [#{} #{:git/url}] + (fn [lib-sym lib-opts] + (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + {:keys [name commit]} (latest-github-tag lib-sym)] + {lib-sym {:git/url url :git/tag name :git/sha (:sha commit)}})) + + [#{:git/tag} #{:git/url :git/tag}] + (fn [lib-sym lib-opts] + (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + tag (:git/tag lib-opts) + commit (->> (list-tags lib-sym) + (filter #(= (:name %) tag)) + first + :commit)] + {lib-sym {:git/url url :git/tag tag :git/sha (:sha commit)}})) + + [#{:git/sha} #{:git/url :git/sha}] + (fn [lib-sym lib-opts] + (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + sha (:git/sha lib-opts)] + {lib-sym {:git/url url :git/sha sha}})) + + [#{:git/url :git/tag :git/sha}] + (fn [lib-sym lib-opts] + {lib-sym (select-keys lib-opts [:git/url :git/tag :git/sha])})}) + (def valid-lib-opts - #{#{:local/root} - - #{} - #{:git/url} - - #{:git/tag} - #{:git/url :git/tag} - - #{:git/sha} - #{:git/url :git/sha} - - #{:git/url :git/tag :git/sha}}) - -(defn invalid-lib-opts-message [lib-opts] - (str "Requires one of the following combinations of lib options:\n" - (pr-str valid-lib-opts) "\n\n" - "Provided:\n" - (pr-str lib-opts))) - -(defn- template-libs [template opts] - (let [lib-opts (set (keys (select-keys opts (into #{} cat valid-lib-opts)))) - lib-sym (edn/read-string template)] - (case lib-opts - (#{:local/root}) - {lib-sym (select-keys opts [:local/root])} - - (#{} - #{:git/url}) - (let [url (or (:git/url opts) (github-repo-url lib-sym)) - {:keys [name commit]} (latest-github-tag lib-sym)] - {lib-sym {:git/url url :git/tag name :git/sha (:sha commit)}}) - - (#{:git/tag} - #{:git/url :git/tag}) - (let [url (or (:git/url opts) (github-repo-url lib-sym)) - tag (:git/tag opts) - commit (->> (list-tags lib-sym) - (filter #(= (:name %) tag)) - first - :commit)] - {lib-sym {:git/url url :git/tag tag :git/sha (:sha commit)}}) - - (#{:git/sha} - #{:git/url :git/sha}) - (let [url (or (:git/url opts) (github-repo-url lib-sym)) - sha (:git/sha opts)] - {lib-sym {:git/url url :git/sha sha}}) - - #{:git/url :git/tag :git/sha} - {lib-sym (select-keys opts [:git/url :git/tag :git/sha])} - - (throw (ex-info (invalid-lib-opts-message lib-opts) {}))))) - -(defn- set-class-path-property [] + "The set of all valid combinations of deps-new template deps opts." + (into #{} cat (keys lib-opts->template-deps-fn))) + +(defn- deps-new-cli-opts->lib-opts + "Returns parsed deps-new template deps opts from raw CLI opts." + [cli-opts] + (select-keys cli-opts (into #{} cat valid-lib-opts))) + +(defn- invalid-lib-opts-error [provided-lib-opts] + (ex-info (str "Provided invalid combination of CLI options for deps-new " + "template deps.") + {:provided-opts (set (keys provided-lib-opts)) + :valid-combinations valid-lib-opts})) + +(defn- find-template-deps-fn + "Returns a template-deps-fn given lib-opts parsed from raw CLI opts." + [lib-opts] + (some (fn [[k v]] (and (contains? (set k) (set (keys lib-opts))) v)) + lib-opts->template-deps-fn)) + +(defn- template-deps + "Returns a tools.deps lib map for the given CLI opts." + [template cli-opts] + (let [lib-opts (deps-new-cli-opts->lib-opts cli-opts) + lib-sym (edn/read-string template) + template-deps-fn (find-template-deps-fn lib-opts)] + (if-not template-deps-fn + (throw (invalid-lib-opts-error lib-opts)) + (template-deps-fn lib-sym lib-opts)))) + +(defn- set-class-path-property + "Sets the java.class.path property to the current classpath. + + This needs to be called before running org.corfield.new/create." + [] (System/setProperty "java.class.path" (cp/get-classpath))) -(defn- deps-new-plan [cli-opts] +(defn- deps-new-plan + "Returns a plan for calling org.corfield.new/create. + + :template-deps - These deps will be added with babashka.deps/add-deps before + calling the create function. + + :create-opts - This map contains the options that will be passed to the + create function." + [cli-opts] (let [create-opts (merge {:template "scratch"} (dissoc cli-opts :dry-run :deps-file)) - template-deps (when-not (built-in-template? (:template create-opts)) - (template-libs (:template create-opts) cli-opts))] - {:template-deps template-deps + tpl-deps (when-not (built-in-template? (:template create-opts)) + (template-deps (:template create-opts) cli-opts))] + {:template-deps tpl-deps :create-opts create-opts})) (defn- deps-new-create [create-opts] ((requiring-resolve 'org.corfield.new/create) create-opts)) -(defn run-deps-new [{:keys [opts]}] +(defn run-deps-new + "Runs org.corfield.new/create using the provided CLI options. + + To support the dry run feature, side-effects should be described in the plan + provided by deps-new-plan. This function's job is to execute side-effects + using the plan to provide repeatability." + [{:keys [opts]}] (require 'org.corfield.new) (let [plan (deps-new-plan opts) {:keys [template-deps create-opts]} plan] From 1a8243df5a2ea1499cb772c92c805103f9b33bfb Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Wed, 27 Jul 2022 18:45:32 -0700 Subject: [PATCH 13/25] Add support for :sha and :latest-sha --- neil | 11 ++++++++++- src/babashka/neil.clj | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/neil b/neil index 276aab9..0c961ed 100755 --- a/neil +++ b/neil @@ -25,6 +25,7 @@ '[borkdude.rewrite-edn :as r] '[cheshire.core :as cheshire] '[clojure.edn :as edn] + '[clojure.set :as set] '[clojure.string :as str]) (def spec {:lib {:desc "Fully qualified library name."} @@ -415,6 +416,12 @@ sha (:git/sha lib-opts)] {lib-sym {:git/url url :git/sha sha}})) + [#{:latest-sha} #{:git/url :latest-sha}] + (fn [lib-sym lib-opts] + (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + sha (latest-github-sha lib-sym)] + {lib-sym {:git/url url :git/sha sha}})) + [#{:git/url :git/tag :git/sha}] (fn [lib-sym lib-opts] {lib-sym (select-keys lib-opts [:git/url :git/tag :git/sha])})}) @@ -426,7 +433,9 @@ (defn- deps-new-cli-opts->lib-opts "Returns parsed deps-new template deps opts from raw CLI opts." [cli-opts] - (select-keys cli-opts (into #{} cat valid-lib-opts))) + (-> cli-opts + (set/rename-keys {:sha :git/sha}) + (select-keys (into #{} cat valid-lib-opts)))) (defn- invalid-lib-opts-error [provided-lib-opts] (ex-info (str "Provided invalid combination of CLI options for deps-new " diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 09dd35c..254a30f 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -9,6 +9,7 @@ '[borkdude.rewrite-edn :as r] '[cheshire.core :as cheshire] '[clojure.edn :as edn] + '[clojure.set :as set] '[clojure.string :as str]) (def spec {:lib {:desc "Fully qualified library name."} @@ -399,6 +400,12 @@ sha (:git/sha lib-opts)] {lib-sym {:git/url url :git/sha sha}})) + [#{:latest-sha} #{:git/url :latest-sha}] + (fn [lib-sym lib-opts] + (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + sha (latest-github-sha lib-sym)] + {lib-sym {:git/url url :git/sha sha}})) + [#{:git/url :git/tag :git/sha}] (fn [lib-sym lib-opts] {lib-sym (select-keys lib-opts [:git/url :git/tag :git/sha])})}) @@ -410,7 +417,9 @@ (defn- deps-new-cli-opts->lib-opts "Returns parsed deps-new template deps opts from raw CLI opts." [cli-opts] - (select-keys cli-opts (into #{} cat valid-lib-opts))) + (-> cli-opts + (set/rename-keys {:sha :git/sha}) + (select-keys (into #{} cat valid-lib-opts)))) (defn- invalid-lib-opts-error [provided-lib-opts] (ex-info (str "Provided invalid combination of CLI options for deps-new " From 6369e5e64a07b7e60397a5141cd27d48495225af Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Wed, 27 Jul 2022 19:24:01 -0700 Subject: [PATCH 14/25] Update help --- neil | 37 ++++++++++++++++++++++++++++++++++--- src/babashka/neil.clj | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/neil b/neil index 0c961ed..469fcf4 100755 --- a/neil +++ b/neil @@ -525,14 +525,45 @@ dep add: Adds --lib, a fully qualified symbol, to deps.edn :deps. Run neil add dep --help to see all options. -new: Create a new project using deps-new - Runs one of the template functions in org.corfield.new. +new: + Create a project using deps-new + + Usage: + neil new template name [target-dir] [template-opts] + + Runs the org.corfield.new/create function. All of the deps-new options can be + provided as CLI options: - See the deps-new docs for all available options: https://github.com/seancorfield/deps-new/blob/develop/doc/options.md + Both built-in and remote templates are supported. Built-in templates use + unqualified names (e.g. scratch) whereas remote templates use fully-qualified + names (e.g. io.github.kit/kit-clj). + + If a remote template is provided, the babashka.deps/add-deps function will be + called automatically before running org.corfield.new/create. The deps for the + template are inferred automatically from the template name. The following + options can be used to control the add-deps behavior: + + --git/url + Override the :git/url in the :deps map. If no URL is provided, a template + name starting with io.github is expected and the URL will point to GitHub. + + --git/tag + Override the :git/tag in the :deps map. If no SHA or tag is provided, the + latest tag from the default branch on GitHub will be used. + + --sha --git/sha + Override the :git/sha in the :deps map. If no SHA is provided, the latest + tag for the default branch from GitHub will be used. + + --latest-sha + Override the :git/sha in the :deps map with the latest SHA from the + default branch on GitHub. + Examples: neil new scratch foo --overwrite + neil new io.github.rads/neil-new-test-template foo2 --latest-sha license list Lists commonly-used licenses available to be added to project. Takes an optional search string to filter results. diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 254a30f..0339b96 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -509,14 +509,45 @@ dep add: Adds --lib, a fully qualified symbol, to deps.edn :deps. Run neil add dep --help to see all options. -new: Create a new project using deps-new - Runs one of the template functions in org.corfield.new. +new: + Create a project using deps-new + + Usage: + neil new template name [target-dir] [template-opts] + + Runs the org.corfield.new/create function. All of the deps-new options can be + provided as CLI options: - See the deps-new docs for all available options: https://github.com/seancorfield/deps-new/blob/develop/doc/options.md + Both built-in and remote templates are supported. Built-in templates use + unqualified names (e.g. scratch) whereas remote templates use fully-qualified + names (e.g. io.github.kit/kit-clj). + + If a remote template is provided, the babashka.deps/add-deps function will be + called automatically before running org.corfield.new/create. The deps for the + template are inferred automatically from the template name. The following + options can be used to control the add-deps behavior: + + --git/url + Override the :git/url in the :deps map. If no URL is provided, a template + name starting with io.github is expected and the URL will point to GitHub. + + --git/tag + Override the :git/tag in the :deps map. If no SHA or tag is provided, the + latest tag from the default branch on GitHub will be used. + + --sha --git/sha + Override the :git/sha in the :deps map. If no SHA is provided, the latest + tag for the default branch from GitHub will be used. + + --latest-sha + Override the :git/sha in the :deps map with the latest SHA from the + default branch on GitHub. + Examples: neil new scratch foo --overwrite + neil new io.github.rads/neil-new-test-template foo2 --latest-sha license list Lists commonly-used licenses available to be added to project. Takes an optional search string to filter results. From 8c149dda925c65804505dd87aefb110a9f8a067d Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Wed, 27 Jul 2022 20:31:12 -0700 Subject: [PATCH 15/25] Infer GitHub repo from :git/url instead of :template --- neil | 30 ++++++++++++++++++++++-------- src/babashka/neil.clj | 30 ++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/neil b/neil index 469fcf4..6ac144a 100755 --- a/neil +++ b/neil @@ -382,9 +382,23 @@ [template] (contains? (set (map name (keys (ns-publics 'org.corfield.new)))) template)) -(defn- github-repo-url [lib] +(defn- github-repo-http-url [lib] (str "https://github.com/" (clean-github-lib lib))) +(def github-repo-ssh-regex #"^git@github.com:([^/]+)/([^\.]+)\.git$") +(def github-repo-http-regex #"^https://github.com/([^/]+)/([^\.]+)(\.git)?$") + +(defn- parse-git-url [git-url] + (let [[[_ gh-user repo-name]] (or (re-seq github-repo-ssh-regex git-url) + (re-seq github-repo-http-regex git-url))] + (if (and gh-user repo-name) + {:gh-user gh-user :repo-name repo-name} + (throw (ex-info "Failed to parse :git/url" {:git/url git-url}))))) + +(defn- git-url->lib-sym [git-url] + (when-let [{:keys [gh-user repo-name]} (parse-git-url git-url)] + (symbol (str "io.github." gh-user) repo-name))) + (def lib-opts->template-deps-fn "A map to define valid CLI options for deps-new template deps. @@ -396,15 +410,15 @@ [#{} #{:git/url}] (fn [lib-sym lib-opts] - (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) - {:keys [name commit]} (latest-github-tag lib-sym)] + (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) + {:keys [name commit]} (latest-github-tag (git-url->lib-sym url))] {lib-sym {:git/url url :git/tag name :git/sha (:sha commit)}})) [#{:git/tag} #{:git/url :git/tag}] (fn [lib-sym lib-opts] - (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) tag (:git/tag lib-opts) - commit (->> (list-tags lib-sym) + commit (->> (list-tags (git-url->lib-sym url)) (filter #(= (:name %) tag)) first :commit)] @@ -412,14 +426,14 @@ [#{:git/sha} #{:git/url :git/sha}] (fn [lib-sym lib-opts] - (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) sha (:git/sha lib-opts)] {lib-sym {:git/url url :git/sha sha}})) [#{:latest-sha} #{:git/url :latest-sha}] (fn [lib-sym lib-opts] - (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) - sha (latest-github-sha lib-sym)] + (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) + sha (latest-github-sha (git-url->lib-sym url))] {lib-sym {:git/url url :git/sha sha}})) [#{:git/url :git/tag :git/sha}] diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 0339b96..aede06c 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -366,9 +366,23 @@ [template] (contains? (set (map name (keys (ns-publics 'org.corfield.new)))) template)) -(defn- github-repo-url [lib] +(defn- github-repo-http-url [lib] (str "https://github.com/" (clean-github-lib lib))) +(def github-repo-ssh-regex #"^git@github.com:([^/]+)/([^\.]+)\.git$") +(def github-repo-http-regex #"^https://github.com/([^/]+)/([^\.]+)(\.git)?$") + +(defn- parse-git-url [git-url] + (let [[[_ gh-user repo-name]] (or (re-seq github-repo-ssh-regex git-url) + (re-seq github-repo-http-regex git-url))] + (if (and gh-user repo-name) + {:gh-user gh-user :repo-name repo-name} + (throw (ex-info "Failed to parse :git/url" {:git/url git-url}))))) + +(defn- git-url->lib-sym [git-url] + (when-let [{:keys [gh-user repo-name]} (parse-git-url git-url)] + (symbol (str "io.github." gh-user) repo-name))) + (def lib-opts->template-deps-fn "A map to define valid CLI options for deps-new template deps. @@ -380,15 +394,15 @@ [#{} #{:git/url}] (fn [lib-sym lib-opts] - (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) - {:keys [name commit]} (latest-github-tag lib-sym)] + (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) + {:keys [name commit]} (latest-github-tag (git-url->lib-sym url))] {lib-sym {:git/url url :git/tag name :git/sha (:sha commit)}})) [#{:git/tag} #{:git/url :git/tag}] (fn [lib-sym lib-opts] - (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) tag (:git/tag lib-opts) - commit (->> (list-tags lib-sym) + commit (->> (list-tags (git-url->lib-sym url)) (filter #(= (:name %) tag)) first :commit)] @@ -396,14 +410,14 @@ [#{:git/sha} #{:git/url :git/sha}] (fn [lib-sym lib-opts] - (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) + (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) sha (:git/sha lib-opts)] {lib-sym {:git/url url :git/sha sha}})) [#{:latest-sha} #{:git/url :latest-sha}] (fn [lib-sym lib-opts] - (let [url (or (:git/url lib-opts) (github-repo-url lib-sym)) - sha (latest-github-sha lib-sym)] + (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) + sha (latest-github-sha (git-url->lib-sym url))] {lib-sym {:git/url url :git/sha sha}})) [#{:git/url :git/tag :git/sha}] From 233eda5864004a73a7baba4e048d8bbad2a44fbd Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Wed, 27 Jul 2022 20:35:28 -0700 Subject: [PATCH 16/25] Update docs --- neil | 11 ++++++----- src/babashka/neil.clj | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/neil b/neil index 6ac144a..0414850 100755 --- a/neil +++ b/neil @@ -561,19 +561,20 @@ new: --git/url Override the :git/url in the :deps map. If no URL is provided, a template - name starting with io.github is expected and the URL will point to GitHub. + name starting with io.github or com.github is expected and the URL will + point to GitHub. --git/tag Override the :git/tag in the :deps map. If no SHA or tag is provided, the - latest tag from the default branch on GitHub will be used. + latest tag from the default branch of :git/url will be used. --sha --git/sha - Override the :git/sha in the :deps map. If no SHA is provided, the latest - tag for the default branch from GitHub will be used. + Override the :git/sha in the :deps map. If no SHA or tag is provided, the + latest tag from the default branch of :git/url will be used. --latest-sha Override the :git/sha in the :deps map with the latest SHA from the - default branch on GitHub. + default branch of :git/url. Examples: neil new scratch foo --overwrite diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index aede06c..3dd64ad 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -545,19 +545,20 @@ new: --git/url Override the :git/url in the :deps map. If no URL is provided, a template - name starting with io.github is expected and the URL will point to GitHub. + name starting with io.github or com.github is expected and the URL will + point to GitHub. --git/tag Override the :git/tag in the :deps map. If no SHA or tag is provided, the - latest tag from the default branch on GitHub will be used. + latest tag from the default branch of :git/url will be used. --sha --git/sha - Override the :git/sha in the :deps map. If no SHA is provided, the latest - tag for the default branch from GitHub will be used. + Override the :git/sha in the :deps map. If no SHA or tag is provided, the + latest tag from the default branch of :git/url will be used. --latest-sha Override the :git/sha in the :deps map with the latest SHA from the - default branch on GitHub. + default branch of :git/url. Examples: neil new scratch foo --overwrite From 619a7b601ca9d03ce4d27f543d8c05dda13ccb70 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Wed, 27 Jul 2022 22:13:04 -0700 Subject: [PATCH 17/25] Move docs to neil new --help --- neil | 94 +++++++++++++++++++++++-------------------- src/babashka/neil.clj | 94 +++++++++++++++++++++++-------------------- 2 files changed, 100 insertions(+), 88 deletions(-) diff --git a/neil b/neil index 0414850..b4689e8 100755 --- a/neil +++ b/neil @@ -499,6 +499,42 @@ (defn- deps-new-create [create-opts] ((requiring-resolve 'org.corfield.new/create) create-opts)) +(defn print-new-help [] + (println (str/trim " +Usage: neil new [template] [name] [target-dir] [options] + +Runs the org.corfield.new/create function from deps-new. + +All of the deps-new options can be provided as CLI options: + +https://github.com/seancorfield/deps-new/blob/develop/doc/options.md + +Both built-in and remote templates are supported. Built-in templates use +unqualified names (e.g. scratch) whereas remote templates use fully-qualified +names (e.g. io.github.kit/kit-clj). + +If a remote template is provided, the babashka.deps/add-deps function will be +called automatically before running org.corfield.new/create. The deps for the +template are inferred automatically from the template name. The following +options can be used to control the add-deps behavior: + + --git/url + Override the :git/url in the :deps map. If no URL is provided, a template + name starting with io.github or com.github is expected and the URL will + point to GitHub. + + --git/tag + Override the :git/tag in the :deps map. If no SHA or tag is provided, the + latest tag from the default branch of :git/url will be used. + + --sha --git/sha + Override the :git/sha in the :deps map. If no SHA or tag is provided, the + latest tag from the default branch of :git/url will be used. + + --latest-sha + Override the :git/sha in the :deps map with the latest SHA from the + default branch of :git/url."))) + (defn run-deps-new "Runs org.corfield.new/create using the provided CLI options. @@ -506,16 +542,19 @@ provided by deps-new-plan. This function's job is to execute side-effects using the plan to provide repeatability." [{:keys [opts]}] - (require 'org.corfield.new) - (let [plan (deps-new-plan opts) - {:keys [template-deps create-opts]} plan] - (if (:dry-run opts) - plan - (do - (when template-deps (deps/add-deps {:deps template-deps})) - (set-class-path-property) - (deps-new-create create-opts) - nil)))) + (if (:help opts) + (print-new-help) + (do + (require 'org.corfield.new) + (let [plan (deps-new-plan opts) + {:keys [template-deps create-opts]} plan] + (if (:dry-run opts) + plan + (do + (when template-deps (deps/add-deps {:deps template-deps})) + (set-class-path-property) + (deps-new-create create-opts) + nil)))))) (defn print-help [_] (println (str/trim " @@ -541,40 +580,7 @@ dep new: Create a project using deps-new - - Usage: - neil new template name [target-dir] [template-opts] - - Runs the org.corfield.new/create function. All of the deps-new options can be - provided as CLI options: - - https://github.com/seancorfield/deps-new/blob/develop/doc/options.md - - Both built-in and remote templates are supported. Built-in templates use - unqualified names (e.g. scratch) whereas remote templates use fully-qualified - names (e.g. io.github.kit/kit-clj). - - If a remote template is provided, the babashka.deps/add-deps function will be - called automatically before running org.corfield.new/create. The deps for the - template are inferred automatically from the template name. The following - options can be used to control the add-deps behavior: - - --git/url - Override the :git/url in the :deps map. If no URL is provided, a template - name starting with io.github or com.github is expected and the URL will - point to GitHub. - - --git/tag - Override the :git/tag in the :deps map. If no SHA or tag is provided, the - latest tag from the default branch of :git/url will be used. - - --sha --git/sha - Override the :git/sha in the :deps map. If no SHA or tag is provided, the - latest tag from the default branch of :git/url will be used. - - --latest-sha - Override the :git/sha in the :deps map with the latest SHA from the - default branch of :git/url. + Run neil new --help to see all options. Examples: neil new scratch foo --overwrite diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 3dd64ad..1e9802a 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -483,6 +483,42 @@ (defn- deps-new-create [create-opts] ((requiring-resolve 'org.corfield.new/create) create-opts)) +(defn print-new-help [] + (println (str/trim " +Usage: neil new [template] [name] [target-dir] [options] + +Runs the org.corfield.new/create function from deps-new. + +All of the deps-new options can be provided as CLI options: + +https://github.com/seancorfield/deps-new/blob/develop/doc/options.md + +Both built-in and remote templates are supported. Built-in templates use +unqualified names (e.g. scratch) whereas remote templates use fully-qualified +names (e.g. io.github.kit/kit-clj). + +If a remote template is provided, the babashka.deps/add-deps function will be +called automatically before running org.corfield.new/create. The deps for the +template are inferred automatically from the template name. The following +options can be used to control the add-deps behavior: + + --git/url + Override the :git/url in the :deps map. If no URL is provided, a template + name starting with io.github or com.github is expected and the URL will + point to GitHub. + + --git/tag + Override the :git/tag in the :deps map. If no SHA or tag is provided, the + latest tag from the default branch of :git/url will be used. + + --sha --git/sha + Override the :git/sha in the :deps map. If no SHA or tag is provided, the + latest tag from the default branch of :git/url will be used. + + --latest-sha + Override the :git/sha in the :deps map with the latest SHA from the + default branch of :git/url."))) + (defn run-deps-new "Runs org.corfield.new/create using the provided CLI options. @@ -490,16 +526,19 @@ provided by deps-new-plan. This function's job is to execute side-effects using the plan to provide repeatability." [{:keys [opts]}] - (require 'org.corfield.new) - (let [plan (deps-new-plan opts) - {:keys [template-deps create-opts]} plan] - (if (:dry-run opts) - plan - (do - (when template-deps (deps/add-deps {:deps template-deps})) - (set-class-path-property) - (deps-new-create create-opts) - nil)))) + (if (:help opts) + (print-new-help) + (do + (require 'org.corfield.new) + (let [plan (deps-new-plan opts) + {:keys [template-deps create-opts]} plan] + (if (:dry-run opts) + plan + (do + (when template-deps (deps/add-deps {:deps template-deps})) + (set-class-path-property) + (deps-new-create create-opts) + nil)))))) (defn print-help [_] (println (str/trim " @@ -525,40 +564,7 @@ dep new: Create a project using deps-new - - Usage: - neil new template name [target-dir] [template-opts] - - Runs the org.corfield.new/create function. All of the deps-new options can be - provided as CLI options: - - https://github.com/seancorfield/deps-new/blob/develop/doc/options.md - - Both built-in and remote templates are supported. Built-in templates use - unqualified names (e.g. scratch) whereas remote templates use fully-qualified - names (e.g. io.github.kit/kit-clj). - - If a remote template is provided, the babashka.deps/add-deps function will be - called automatically before running org.corfield.new/create. The deps for the - template are inferred automatically from the template name. The following - options can be used to control the add-deps behavior: - - --git/url - Override the :git/url in the :deps map. If no URL is provided, a template - name starting with io.github or com.github is expected and the URL will - point to GitHub. - - --git/tag - Override the :git/tag in the :deps map. If no SHA or tag is provided, the - latest tag from the default branch of :git/url will be used. - - --sha --git/sha - Override the :git/sha in the :deps map. If no SHA or tag is provided, the - latest tag from the default branch of :git/url will be used. - - --latest-sha - Override the :git/sha in the :deps map with the latest SHA from the - default branch of :git/url. + Run neil new --help to see all options. Examples: neil new scratch foo --overwrite From 57d9a3e0ba69374afdf18fa61b8db1088ccd8bbf Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Wed, 27 Jul 2022 22:16:28 -0700 Subject: [PATCH 18/25] Add --local/root to docs --- neil | 6 +++++- src/babashka/neil.clj | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/neil b/neil index b4689e8..f36c26a 100755 --- a/neil +++ b/neil @@ -518,6 +518,9 @@ called automatically before running org.corfield.new/create. The deps for the template are inferred automatically from the template name. The following options can be used to control the add-deps behavior: + --local/root + Override the :deps map to use the provided :local/root path. + --git/url Override the :git/url in the :deps map. If no URL is provided, a template name starting with io.github or com.github is expected and the URL will @@ -527,7 +530,8 @@ options can be used to control the add-deps behavior: Override the :git/tag in the :deps map. If no SHA or tag is provided, the latest tag from the default branch of :git/url will be used. - --sha --git/sha + --sha + --git/sha Override the :git/sha in the :deps map. If no SHA or tag is provided, the latest tag from the default branch of :git/url will be used. diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 1e9802a..cfa7917 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -502,6 +502,9 @@ called automatically before running org.corfield.new/create. The deps for the template are inferred automatically from the template name. The following options can be used to control the add-deps behavior: + --local/root + Override the :deps map to use the provided :local/root path. + --git/url Override the :git/url in the :deps map. If no URL is provided, a template name starting with io.github or com.github is expected and the URL will @@ -511,7 +514,8 @@ options can be used to control the add-deps behavior: Override the :git/tag in the :deps map. If no SHA or tag is provided, the latest tag from the default branch of :git/url will be used. - --sha --git/sha + --sha + --git/sha Override the :git/sha in the :deps map. If no SHA or tag is provided, the latest tag from the default branch of :git/url will be used. From d3693fff026b6b5be751a022f6c9e6aaeab554f0 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Wed, 27 Jul 2022 22:43:12 -0700 Subject: [PATCH 19/25] Add create-opts-deny-list --- neil | 5 ++++- src/babashka/neil.clj | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/neil b/neil index f36c26a..cc12fbe 100755 --- a/neil +++ b/neil @@ -480,6 +480,9 @@ [] (System/setProperty "java.class.path" (cp/get-classpath))) +(def create-opts-deny-list + [:deps-file :dry-run :git/sha :git/url :latest-sha :local/root :sha]) + (defn- deps-new-plan "Returns a plan for calling org.corfield.new/create. @@ -490,7 +493,7 @@ create function." [cli-opts] (let [create-opts (merge {:template "scratch"} - (dissoc cli-opts :dry-run :deps-file)) + (apply dissoc cli-opts create-opts-deny-list)) tpl-deps (when-not (built-in-template? (:template create-opts)) (template-deps (:template create-opts) cli-opts))] {:template-deps tpl-deps diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index cfa7917..ba70661 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -464,6 +464,9 @@ [] (System/setProperty "java.class.path" (cp/get-classpath))) +(def create-opts-deny-list + [:deps-file :dry-run :git/sha :git/url :latest-sha :local/root :sha]) + (defn- deps-new-plan "Returns a plan for calling org.corfield.new/create. @@ -474,7 +477,7 @@ create function." [cli-opts] (let [create-opts (merge {:template "scratch"} - (dissoc cli-opts :dry-run :deps-file)) + (apply dissoc cli-opts create-opts-deny-list)) tpl-deps (when-not (built-in-template? (:template create-opts)) (template-deps (:template create-opts) cli-opts))] {:template-deps tpl-deps From 471d6fe715d1fbb7732e7b8a86c4da55e4417d6b Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Wed, 27 Jul 2022 22:53:30 -0700 Subject: [PATCH 20/25] Clean up duplicated code --- neil | 18 +++++++++--------- src/babashka/neil.clj | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/neil b/neil index cc12fbe..b2e024c 100755 --- a/neil +++ b/neil @@ -112,16 +112,19 @@ (namespace lib) (name lib) branch)) :sha))) -(defn list-tags [lib] +(defn list-github-tags [lib] (let [lib (clean-github-lib lib)] (curl-get-json (format "https://api.github.com/repos/%s/%s/tags" (namespace lib) (name lib))))) (defn latest-github-tag [lib] - (let [lib (clean-github-lib lib)] - (first - (curl-get-json (format "https://api.github.com/repos/%s/%s/tags" - (namespace lib) (name lib)))))) + (-> (list-github-tags lib) + first)) + +(defn find-github-tag [lib tag] + (->> (list-github-tags lib) + (filter #(= (:name %) tag)) + first)) (def deps-template (str/triml " @@ -418,10 +421,7 @@ (fn [lib-sym lib-opts] (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) tag (:git/tag lib-opts) - commit (->> (list-tags (git-url->lib-sym url)) - (filter #(= (:name %) tag)) - first - :commit)] + {:keys [commit]} (find-github-tag (git-url->lib-sym url) tag)] {lib-sym {:git/url url :git/tag tag :git/sha (:sha commit)}})) [#{:git/sha} #{:git/url :git/sha}] diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index ba70661..451f2fe 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -96,16 +96,19 @@ (namespace lib) (name lib) branch)) :sha))) -(defn list-tags [lib] +(defn list-github-tags [lib] (let [lib (clean-github-lib lib)] (curl-get-json (format "https://api.github.com/repos/%s/%s/tags" (namespace lib) (name lib))))) (defn latest-github-tag [lib] - (let [lib (clean-github-lib lib)] - (first - (curl-get-json (format "https://api.github.com/repos/%s/%s/tags" - (namespace lib) (name lib)))))) + (-> (list-github-tags lib) + first)) + +(defn find-github-tag [lib tag] + (->> (list-github-tags lib) + (filter #(= (:name %) tag)) + first)) (def deps-template (str/triml " @@ -402,10 +405,7 @@ (fn [lib-sym lib-opts] (let [url (or (:git/url lib-opts) (github-repo-http-url lib-sym)) tag (:git/tag lib-opts) - commit (->> (list-tags (git-url->lib-sym url)) - (filter #(= (:name %) tag)) - first - :commit)] + {:keys [commit]} (find-github-tag (git-url->lib-sym url) tag)] {lib-sym {:git/url url :git/tag tag :git/sha (:sha commit)}})) [#{:git/sha} #{:git/url :git/sha}] From cc7bc47a51ad664291f6673c47daa3b0f8f7d19b Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Fri, 29 Jul 2022 04:52:19 -0700 Subject: [PATCH 21/25] Fix Clojure compatibility --- neil | 34 ++++++++++++++++++---------------- src/babashka/neil.clj | 34 ++++++++++++++++++---------------- tests.clj | 3 +-- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/neil b/neil index b2e024c..cfd9d4e 100755 --- a/neil +++ b/neil @@ -17,10 +17,8 @@ (ns babashka.neil {:no-doc true}) -(require '[babashka.classpath :as cp] - '[babashka.cli :as cli] +(require '[babashka.cli :as cli] '[babashka.curl :as curl] - '[babashka.deps :as deps] '[babashka.fs :as fs] '[borkdude.rewrite-edn :as r] '[cheshire.core :as cheshire] @@ -50,6 +48,8 @@ (def windows? (str/includes? (System/getProperty "os.name") "Windows")) +(def bb? (System/getProperty "babashka.version")) + (defn url-encode [s] (URLEncoder/encode s "UTF-8")) (def curl-opts @@ -473,13 +473,6 @@ (throw (invalid-lib-opts-error lib-opts)) (template-deps-fn lib-sym lib-opts)))) -(defn- set-class-path-property - "Sets the java.class.path property to the current classpath. - - This needs to be called before running org.corfield.new/create." - [] - (System/setProperty "java.class.path" (cp/get-classpath))) - (def create-opts-deny-list [:deps-file :dry-run :git/sha :git/url :latest-sha :local/root :sha]) @@ -494,10 +487,10 @@ [cli-opts] (let [create-opts (merge {:template "scratch"} (apply dissoc cli-opts create-opts-deny-list)) - tpl-deps (when-not (built-in-template? (:template create-opts)) + tpl-deps (when (and bb? (not (built-in-template? (:template create-opts)))) (template-deps (:template create-opts) cli-opts))] - {:template-deps tpl-deps - :create-opts create-opts})) + (merge (when tpl-deps {:template-deps tpl-deps}) + {:create-opts create-opts}))) (defn- deps-new-create [create-opts] ((requiring-resolve 'org.corfield.new/create) create-opts)) @@ -542,6 +535,16 @@ options can be used to control the add-deps behavior: Override the :git/sha in the :deps map with the latest SHA from the default branch of :git/url."))) +(defn- deps-new-add-template-deps + "Adds template deps at runtime and sets the java.class.path. + + The java.class.path property is used by org.corfield.new/create to find + templates." + [template-deps] + (let [_ ((requiring-resolve 'babashka.deps/add-deps) {:deps template-deps}) + cp ((requiring-resolve 'babashka.classpath/get-classpath))] + (System/setProperty "java.class.path" cp))) + (defn run-deps-new "Runs org.corfield.new/create using the provided CLI options. @@ -556,10 +559,9 @@ options can be used to control the add-deps behavior: (let [plan (deps-new-plan opts) {:keys [template-deps create-opts]} plan] (if (:dry-run opts) - plan + (do (pr plan) nil) (do - (when template-deps (deps/add-deps {:deps template-deps})) - (set-class-path-property) + (when template-deps (deps-new-add-template-deps template-deps)) (deps-new-create create-opts) nil)))))) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 451f2fe..7e184d7 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -1,10 +1,8 @@ (ns babashka.neil {:no-doc true}) -(require '[babashka.classpath :as cp] - '[babashka.cli :as cli] +(require '[babashka.cli :as cli] '[babashka.curl :as curl] - '[babashka.deps :as deps] '[babashka.fs :as fs] '[borkdude.rewrite-edn :as r] '[cheshire.core :as cheshire] @@ -34,6 +32,8 @@ (def windows? (str/includes? (System/getProperty "os.name") "Windows")) +(def bb? (System/getProperty "babashka.version")) + (defn url-encode [s] (URLEncoder/encode s "UTF-8")) (def curl-opts @@ -457,13 +457,6 @@ (throw (invalid-lib-opts-error lib-opts)) (template-deps-fn lib-sym lib-opts)))) -(defn- set-class-path-property - "Sets the java.class.path property to the current classpath. - - This needs to be called before running org.corfield.new/create." - [] - (System/setProperty "java.class.path" (cp/get-classpath))) - (def create-opts-deny-list [:deps-file :dry-run :git/sha :git/url :latest-sha :local/root :sha]) @@ -478,10 +471,10 @@ [cli-opts] (let [create-opts (merge {:template "scratch"} (apply dissoc cli-opts create-opts-deny-list)) - tpl-deps (when-not (built-in-template? (:template create-opts)) + tpl-deps (when (and bb? (not (built-in-template? (:template create-opts)))) (template-deps (:template create-opts) cli-opts))] - {:template-deps tpl-deps - :create-opts create-opts})) + (merge (when tpl-deps {:template-deps tpl-deps}) + {:create-opts create-opts}))) (defn- deps-new-create [create-opts] ((requiring-resolve 'org.corfield.new/create) create-opts)) @@ -526,6 +519,16 @@ options can be used to control the add-deps behavior: Override the :git/sha in the :deps map with the latest SHA from the default branch of :git/url."))) +(defn- deps-new-add-template-deps + "Adds template deps at runtime and sets the java.class.path. + + The java.class.path property is used by org.corfield.new/create to find + templates." + [template-deps] + (let [_ ((requiring-resolve 'babashka.deps/add-deps) {:deps template-deps}) + cp ((requiring-resolve 'babashka.classpath/get-classpath))] + (System/setProperty "java.class.path" cp))) + (defn run-deps-new "Runs org.corfield.new/create using the provided CLI options. @@ -540,10 +543,9 @@ options can be used to control the add-deps behavior: (let [plan (deps-new-plan opts) {:keys [template-deps create-opts]} plan] (if (:dry-run opts) - plan + (do (pr plan) nil) (do - (when template-deps (deps/add-deps {:deps template-deps})) - (set-class-path-property) + (when template-deps (deps-new-add-template-deps template-deps)) (deps-new-create create-opts) nil)))))) diff --git a/tests.clj b/tests.clj index b764126..cd5aa61 100644 --- a/tests.clj +++ b/tests.clj @@ -94,8 +94,7 @@ ":target-dir" target-dir ":dry-run" "true" ":overwrite" "true")] - (is (= {:template-deps nil - :create-opts {:template "scratch" + (is (= {:create-opts {:template "scratch" :overwrite true :target-dir target-dir :name "my-scratch"}} From e08f386ed7a8b56bf82de83f1d92ec7e216e514d Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Fri, 29 Jul 2022 05:03:16 -0700 Subject: [PATCH 22/25] Use prn instead of pr --- neil | 2 +- src/babashka/neil.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/neil b/neil index cfd9d4e..8de0461 100755 --- a/neil +++ b/neil @@ -559,7 +559,7 @@ options can be used to control the add-deps behavior: (let [plan (deps-new-plan opts) {:keys [template-deps create-opts]} plan] (if (:dry-run opts) - (do (pr plan) nil) + (do (prn plan) nil) (do (when template-deps (deps-new-add-template-deps template-deps)) (deps-new-create create-opts) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index 7e184d7..c8dd94a 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -543,7 +543,7 @@ options can be used to control the add-deps behavior: (let [plan (deps-new-plan opts) {:keys [template-deps create-opts]} plan] (if (:dry-run opts) - (do (pr plan) nil) + (do (prn plan) nil) (do (when template-deps (deps-new-add-template-deps template-deps)) (deps-new-create create-opts) From f838cd7a7b811e7dcbf03cf21ace0d20bbba578a Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Fri, 29 Jul 2022 16:58:16 -0700 Subject: [PATCH 23/25] Use "external" instead of "remote" --- neil | 6 +++--- src/babashka/neil.clj | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/neil b/neil index 8de0461..c6c9489 100755 --- a/neil +++ b/neil @@ -505,11 +505,11 @@ All of the deps-new options can be provided as CLI options: https://github.com/seancorfield/deps-new/blob/develop/doc/options.md -Both built-in and remote templates are supported. Built-in templates use -unqualified names (e.g. scratch) whereas remote templates use fully-qualified +Both built-in and external templates are supported. Built-in templates use +unqualified names (e.g. scratch) whereas external templates use fully-qualified names (e.g. io.github.kit/kit-clj). -If a remote template is provided, the babashka.deps/add-deps function will be +If an external template is provided, the babashka.deps/add-deps function will be called automatically before running org.corfield.new/create. The deps for the template are inferred automatically from the template name. The following options can be used to control the add-deps behavior: diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index c8dd94a..a6b9833 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -489,11 +489,11 @@ All of the deps-new options can be provided as CLI options: https://github.com/seancorfield/deps-new/blob/develop/doc/options.md -Both built-in and remote templates are supported. Built-in templates use -unqualified names (e.g. scratch) whereas remote templates use fully-qualified +Both built-in and external templates are supported. Built-in templates use +unqualified names (e.g. scratch) whereas external templates use fully-qualified names (e.g. io.github.kit/kit-clj). -If a remote template is provided, the babashka.deps/add-deps function will be +If an external template is provided, the babashka.deps/add-deps function will be called automatically before running org.corfield.new/create. The deps for the template are inferred automatically from the template name. The following options can be used to control the add-deps behavior: From 1085be8355c4fc57cc817272362c3ab19611618f Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Fri, 29 Jul 2022 17:35:39 -0700 Subject: [PATCH 24/25] Fix error when using built-in templates from babashka Classpath property must always be set manually when using babashka with deps-new --- neil | 16 +++++++++------- src/babashka/neil.clj | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/neil b/neil index c6c9489..8b0ceae 100755 --- a/neil +++ b/neil @@ -535,15 +535,16 @@ options can be used to control the add-deps behavior: Override the :git/sha in the :deps map with the latest SHA from the default branch of :git/url."))) -(defn- deps-new-add-template-deps - "Adds template deps at runtime and sets the java.class.path. +(defn- deps-new-set-classpath + "The java.class.path required by org.corfield.new/create." + [] + (let [classpath ((requiring-resolve 'babashka.classpath/get-classpath))] + (System/setProperty "java.class.path" classpath))) - The java.class.path property is used by org.corfield.new/create to find - templates." +(defn- deps-new-add-template-deps + "Adds template deps at runtime." [template-deps] - (let [_ ((requiring-resolve 'babashka.deps/add-deps) {:deps template-deps}) - cp ((requiring-resolve 'babashka.classpath/get-classpath))] - (System/setProperty "java.class.path" cp))) + ((requiring-resolve 'babashka.deps/add-deps) {:deps template-deps})) (defn run-deps-new "Runs org.corfield.new/create using the provided CLI options. @@ -562,6 +563,7 @@ options can be used to control the add-deps behavior: (do (prn plan) nil) (do (when template-deps (deps-new-add-template-deps template-deps)) + (when bb? (deps-new-set-classpath)) (deps-new-create create-opts) nil)))))) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index a6b9833..dce8945 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -519,15 +519,16 @@ options can be used to control the add-deps behavior: Override the :git/sha in the :deps map with the latest SHA from the default branch of :git/url."))) -(defn- deps-new-add-template-deps - "Adds template deps at runtime and sets the java.class.path. +(defn- deps-new-set-classpath + "The java.class.path required by org.corfield.new/create." + [] + (let [classpath ((requiring-resolve 'babashka.classpath/get-classpath))] + (System/setProperty "java.class.path" classpath))) - The java.class.path property is used by org.corfield.new/create to find - templates." +(defn- deps-new-add-template-deps + "Adds template deps at runtime." [template-deps] - (let [_ ((requiring-resolve 'babashka.deps/add-deps) {:deps template-deps}) - cp ((requiring-resolve 'babashka.classpath/get-classpath))] - (System/setProperty "java.class.path" cp))) + ((requiring-resolve 'babashka.deps/add-deps) {:deps template-deps})) (defn run-deps-new "Runs org.corfield.new/create using the provided CLI options. @@ -546,6 +547,7 @@ options can be used to control the add-deps behavior: (do (prn plan) nil) (do (when template-deps (deps-new-add-template-deps template-deps)) + (when bb? (deps-new-set-classpath)) (deps-new-create create-opts) nil)))))) From aa6eea6e62ad9e3c5eca263b2ca4141e9e1f8516 Mon Sep 17 00:00:00 2001 From: Radford Smith <11401+rads@users.noreply.github.com> Date: Fri, 29 Jul 2022 17:38:08 -0700 Subject: [PATCH 25/25] Update docstring --- neil | 5 ++++- src/babashka/neil.clj | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/neil b/neil index 8b0ceae..56d8939 100755 --- a/neil +++ b/neil @@ -536,7 +536,10 @@ options can be used to control the add-deps behavior: default branch of :git/url."))) (defn- deps-new-set-classpath - "The java.class.path required by org.corfield.new/create." + "Sets the java.class.path property. + + This is required by org.corfield.new/create. In Clojure it's set by default, + but in Babashka it must be set explicitly." [] (let [classpath ((requiring-resolve 'babashka.classpath/get-classpath))] (System/setProperty "java.class.path" classpath))) diff --git a/src/babashka/neil.clj b/src/babashka/neil.clj index dce8945..19901cb 100644 --- a/src/babashka/neil.clj +++ b/src/babashka/neil.clj @@ -520,7 +520,10 @@ options can be used to control the add-deps behavior: default branch of :git/url."))) (defn- deps-new-set-classpath - "The java.class.path required by org.corfield.new/create." + "Sets the java.class.path property. + + This is required by org.corfield.new/create. In Clojure it's set by default, + but in Babashka it must be set explicitly." [] (let [classpath ((requiring-resolve 'babashka.classpath/get-classpath))] (System/setProperty "java.class.path" classpath)))