-
-
Save jeroenvandijk/6740c1ef7194cb65d0c6c9c5342273f2 to your computer and use it in GitHub Desktop.
Boot tasks in Babashka
This file contains 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 adgoji.application.tasks | |
(:require [spartan.spec :as s])) | |
;; export BABASHKA_CLASSPATH="$(clojure -Sdeps '{:deps {spartan.spec {:git/url "https://github.com/borkdude/spartan.spec" :sha "104129aae9eab6dd4622937d0f46abeed9c9c537"}}}' -Spath)" | |
;; TODO fix adding any? | |
(defn any? [x] | |
true) | |
(defn strlen-1? [x] | |
(= 1 (count (str x)))) | |
(defn strlen-2+? [x] | |
(< 1 (count (str x)))) | |
(s/def ::short-option (s/or ::nil nil? ;; FIXME :nil is not accepted by https://github.com/borkdude/edamame/issues/40 | |
:v (s/and symbol? strlen-1?)) ) | |
(s/def ::long-option (s/or ::nil nil? ;; FIXME :nil is not accepted by https://github.com/borkdude/edamame/issues/40 | |
:v (s/and symbol? strlen-2+?)) ) | |
(defn upper-cased? [x] | |
(let [xs (str x)] | |
(= xs (clojure.string/upper-case xs)))) | |
(defn upper-cased-symbol? [x] | |
(and (symbol? x) | |
(upper-cased? x))) | |
(s/def ::option (s/cat :short-opt ::short-option | |
:long-opt ::long-option | |
:argname (s/? upper-cased-symbol?) | |
:default (s/? (complement upper-cased-symbol?)) ;; DSL extension! | |
:opt-type '#{bool char code edn file float int kw regexp sym str} | |
:desc string?)) | |
(s/def ::options (s/cat :options (s/* ::option))) | |
200 (s/def ::tasks (s/cat | |
:description (s/? string?) | |
:options (s/and vector? ::options) | |
:body (s/* any?))) | |
(def ^:dynamic *options* {}) | |
(defmacro deftask | |
"Define a boot task." | |
[sym & forms] | |
(let [conformed (s/conform ::tasks forms)] | |
(try | |
(if (= ::s/invalid conformed) | |
(do | |
(prn (s/explain ::options forms)) | |
`(println '~forms)) | |
(prn "conformed" conformed) | |
) | |
(catch Exception e | |
(println "eerrro") | |
)) | |
)) | |
;; https://github.com/boot-clj/boot/wiki/Task-Options-DSL | |
(deftask options | |
"Demonstrate the task options DSL." | |
[a a-option VAL 200 kw "The option." | |
c counter int "The counter." | |
e entry VAL sym "An entrypoint symbol." | |
f flag bool "Enable flag." | |
o o-option VAL str "The other option."] | |
*opts*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment