Skip to content

Instantly share code, notes, and snippets.

@arichiardi

arichiardi/boot-rebase.clj

Last active Sep 29, 2016
Embed
What would you like to do?
Boot rebase task
;; https://github.com/boot-clj/boot/pull/398
(defn filter-tmpfiles
"Filter TmpFiles that match (a least one in) metadata-preds.
Metadata-preds is a set of functions which will receive a TmpFile and
tried not in a specific order. If no predicate in the set returns
true-y, the file is filtered out from the returned TmpFiles.
If invert is specified, the behavior is reversed."
([tmpfiles metadata-preds]
(filter-tmpfiles tmpfiles metadata-preds false))
([tmpfiles metadata-preds invert?]
(when (seq metadata-preds)
((if-not invert? filter remove) (apply some-fn metadata-preds) tmpfiles))))
(core/deftask rebase
"A task for moving files with the given metadata from one dir to another"
[w with-meta KEY #{kw} "The set of metadata keys files must have for being rebased."
p path PATH str "The destination path to prepend to the filtered fileset"
v invert bool "Invert the sense of with-meta"]
(core/with-pre-wrap fileset
(let [files (filter-tmpfiles (core/ls fileset) with-meta invert)
paths (map (juxt :path #(str path (:path %))) files)]
(core/commit! (reduce (fn [acc [from-path to-path]]
(merge acc (core/mv acc from-path to-path))) fileset paths)))))
(comment
;; Usage
(comp (built-in/sift :add-meta {#".*" ::initial-fileset})
(built-in/sift :add-jar {'org.clojure/tools.reader clj-one-regex-inclusions})
(rebase :path dest-dir :with-meta #{::initial-fileset} :invert true)
(built-in/show :fileset true)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.