Created
August 23, 2020 07:09
-
-
Save maxp/e374e71ff40e66bc68d09881d1a24526 to your computer and use it in GitHub Desktop.
babashka maker library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns bmk.core | |
(:import | |
[java.time ZonedDateTime] | |
[java.time.format DateTimeFormatter]) | |
(:require | |
[clojure.string :refer [split]] | |
[clojure.java.shell :refer [sh]])) | |
;= | |
(defn cmd [& cmd-args] | |
(let [{:keys [exit out]} (apply sh cmd-args)] | |
(if (= 0 exit) | |
(split out #"\n") | |
(throw (ex-info (str "cmd failed: " (first cmd-args) ) {:exit exit}))))) | |
;; | |
(defn sh-c [args] | |
(let [{:keys [exit out]} (sh "sh" "-c" args)] | |
(if (= 0 exit) | |
(split out #"\n") | |
(throw (ex-info (str "sh-c failed: " args) {:exit exit}))))) | |
;; | |
(defn die [msg] | |
(println msg) | |
(System/exit 1)) | |
;; | |
(defn print-lines [lines] | |
(cond | |
(seq lines ) (doseq [l lines] (println l)) | |
(not (nil? lines)) (println lines) | |
:else nil)) | |
;; | |
(defn git-commit-hash [] | |
(first (cmd "git" "rev-parse" "HEAD"))) | |
;; | |
(defn iso-timestamp [] | |
(.format (DateTimeFormatter/ofPattern "yyyy-MM-dd'T'HH:mm:ssX") (ZonedDateTime/now))) | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment