 (ns leiningen.new.migae
   (:require  [clojure.java.io :as io]
-             [clojure.string :only [join]])
+             [clojure.string :as str])
   (:use
-        [leiningen.new.templates :only [*dir* project-name
-                                        renderer
-                                        render-text
-                                        multi-segment
-                                        sanitize-ns name-to-path
-                                        ->files
-                                        year]]
-        [leiningen.core.main :only [abort]]))
+   [leiningen.new.templates :only [*dir* project-name
+                                   renderer
+                                   render-text
+                                   multi-segment
+                                   sanitize-ns name-to-path
+                                   ->files
+                                   year]]
+   [leiningen.core.main :only [abort]]))
 
 
 (defn- template-path [name path data]

  (let [dir (or *dir*
                (-> (System/getProperty "leiningen.original.pwd")
                    (io/file name) (.getPath)))]
;        foo (println (format "->files dir: %s" dir))]
    (if (or *dir* (.mkdir (io/file dir)))
      (doseq [path paths]
        (do ;(println (format "topath %s" (first path)))
            (println (format "  rendered: %s" (template-path dir (first path) data)))
        (if (string? path)
          (do (println (format "mkdirs %s"  (template-path dir path data)))
              (.mkdirs (template-path dir path data)))
          (let [[path content & options] path
                path (template-path dir path data)
                options (apply hash-map options)]
            (.mkdirs (.getParentFile path))
            (io/copy content (io/file path))
            (when (:executable options)
              (.setExecutable path true)))))
      (println (str "Could not create directory " dir
                      ". Maybe it already exists?"))))))




;; main template entry point
(defn migae

  [projname & args]
  ;; projname syntax:  <clj-app>:<gae-app-id>
  (do
    (cond
     (= projname "app") (make-app projname args)
     (= projname "servlet") (make-servlet projname args)
     :else (println "bad cli"))))
                                        ; (make-app projname args))))
