Lein-LB / src / leiningen / lb.clj

  (:require [ :as ds]))

(def *version* "0.1-SNAPSHOT (uses Liquibase 2.0-RC6)")

;; DSL

(defn help
    (str "
Lein-LB - Lein Liquibase plugin " *version* "

For help on Liquibase commands:

    $ lein lb help

Lein-LB commands (they all begin with a colon):
    :help               prints this help screen
    :sample-properties  prints sample properties to put in

(defn sample-props
  (let [filename "/"
        istream  (.getResourceAsStream String filename)
        owriter  (]
    ;; InputStream resourceAsStream = getClass().getResourceAsStream("/mypackage/mysubpackage/myfile.txt");
    (ds/copy istream owriter)
    (println (.toString owriter))))

(defn execute-liquibase-cmd
  "Execute Liquibase as if using command-line arguments (String array)"
  (liquibase.integration.commandline.Main/main argv))

;; ----- Leiningen plugin command -----

(defn lb
  [& args]
  (let [argc (count args)
        argv (into-array String args)
        cmd  (first args)]
    ;; check for lein-lb commands
      (empty? args)                (help)
      (= cmd ":help")              (help)
      (= cmd ":sample-properties") (sample-props)
      :else                        (execute-liquibase-cmd argv))))