]> njoseph.me Git - babashka-scripts.git/blobdiff - scripts/utils.clj
Add utility to run tasks in the current directory
[babashka-scripts.git] / scripts / utils.clj
index 8ea7664bdc8ade10fcb140a1b5dfea46f922bff7..1de2099b182374b786a7c26e727d34ae16387797 100644 (file)
@@ -1,5 +1,6 @@
 (ns utils
-  (:require [lib :refer [run-cmd]]))
+  (:require [lib :refer [expand-home run-cmd]]
+            [babashka.process :refer [process]]))
 
 (defn run-seq
   "Run a sequence of shell commands on a sequence of arguments.
   (doseq [argument arguments
           command commands]
     (println (run-cmd [command argument]))))
+
+(defn run-task-in-cwd
+  "Run a bb task from this repository in the current working directory."
+  [task]
+  (let [current-dir (System/getenv "PWD")
+        babashka-scripts-dir (expand-home "~/dev/babashka-scripts/")]
+    (print (-> (process ["bb" task current-dir] {:dir babashka-scripts-dir})
+               :out
+               slurp))))