-
-
Save mnewt/eada2e8f3cb9523a6e3f682db7fa2851 to your computer and use it in GitHub Desktop.
command line formatter for clojure using cljfmt
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
#!/usr/bin/env boot | |
;; Format files using cljfmt (https://github.com/weavejester/cljfmt) | |
(set-env! :dependencies '[[cljfmt "0.5.2"]]) | |
(require '[cljfmt.core :as fmt] | |
'[clojure.java.io :as io]) | |
(def help-text | |
"cljfmt: Format files using cljfmt (https://github.com/weavejester/cljfmt) | |
Usage: cljfmt [FILE | DIRECTORY] | |
It will change files in place") | |
(defn fmt-file [f] | |
(println "formatting" (.getName f)) | |
(spit f (fmt/reformat-string (slurp f)))) | |
(defn clj-file? [f] | |
(and (.exists f) (.isFile f) (not (.isHidden f)) | |
(contains? #{"clj" "cljs" "cljc" "cljx" "boot"} | |
(last (.split (.toLowerCase (.getName f)) "\\."))))) | |
(defn fmt [files] | |
(doseq [file files] | |
(let [f (io/file file)] | |
(when (.exists f) | |
(doall (map fmt-file (filter clj-file? (if (.isDirectory f) (file-seq f) [f])))))))) | |
(defn -main [& args] | |
(if (= (first args) "-h") | |
(println help-text) | |
(fmt args))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment