 (defn -main
   ([& [task-name & args]]
      (let [task-name (or (@aliases task-name) task-name "help")
-           project (if (project-needed task-name task-not-found) (read-project))
+           project (if (project-needed? task-name) (read-project))
            compile-path (:compile-path project)]
        (when compile-path (.mkdirs (File. compile-path)))
        (binding [*compile-path* compile-path]

                                  :root root#))))
     (def ~(symbol (name project-name)) project)))

(defn abort [msg]
  (println msg)
  (System/exit 1))

(defn get-home-dir

      (replace \_ \-)
      (replace \/ \.)))

(defn arglists [task-name]
  (:arglists (meta (resolve-task task-name))))

(defn project-needed? [task-name]
  (some #{'project} (map first (arglists task-name))))

(defn matching-arity? [task-name project args]
  (let [arg-count (if (project-needed? task-name)
                    (inc (count args))
                    (count args))]
    (some (fn [defined-args]
            (if (= '& (last (butlast defined-args)))
              (>= arg-count (- (count defined-args) 2))
              (= arg-count (count defined-args))))
      (arglists task-name))))

(defn apply-task [task-name project args not-found]
  (let [task (resolve-task task-name not-found)]
    (if (matching-arity? task-name project args)
      (if (project-needed? task-name)
        (apply task project args)
        (apply task args))
      (abort "Wrong number of arguments to" task-name "task."
             "\nExpected"  (arglists task-name)))))

(def arg-separator ",")

