Permalink
Browse files

Merge pull request #725 from joegallo/task-typos

Task typos
  • Loading branch information...
2 parents 5472099 + 501fb95 commit e48486f7ee02948a1956866488f47251a123315b @technomancy committed Aug 9, 2012
Showing with 50 additions and 17 deletions.
  1. +1 −0 leiningen-core/project.clj
  2. +48 −3 leiningen-core/src/leiningen/core/main.clj
  3. +1 −10 src/leiningen/help.clj
  4. +0 −4 zsh_completion.zsh
@@ -4,6 +4,7 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:description "Library for core functionality of Leiningen."
:dependencies [[org.clojure/clojure "1.4.0"]
+ [bultitude "0.1.7"]
[classlojure "0.6.5"]
[robert/hooke "1.1.2"]
[ordered "1.3.1"]
@@ -3,7 +3,8 @@
[leiningen.core.project :as project]
[leiningen.core.classpath :as classpath]
[clojure.java.io :as io]
- [clojure.string :as string]))
+ [clojure.string :as string]
+ [bultitude.core :as b]))
(def aliases {"-h" "help", "-help" "help", "--help" "help", "-?" "help",
"-v" "version", "-version" "version", "--version" "version",
@@ -19,7 +20,8 @@
(defn lookup-alias [task-name project]
(or (aliases task-name)
(get (:aliases project) task-name)
- task-name "help"))
+ task-name
+ "help"))
(defn task-args [args project]
(if (= "help" (aliases (second args)))
@@ -58,8 +60,51 @@
(apply println msg))
(exit 1)))
+(defn distance [s t]
+ (letfn [(iters [n f start]
+ (take n (map second
+ (iterate f start))))]
+ (let [m (inc (count s)), n (inc (count t))
+ first-row (vec (range m))
+ matrix (iters n (fn [[j row]]
+ [(inc j)
+ (vec (iters m (fn [[i col]]
+ [(inc i)
+ (if (= (nth s i)
+ (nth t j))
+ (get row i)
+ (inc (min (get row i)
+ (get row (inc i))
+ col)))])
+ [0 (inc j)]))])
+ [0 first-row])]
+ (last (last matrix)))))
+
+(defn tasks
+ "Return a list of symbols naming all visible tasks."
+ []
+ (->> (b/namespaces-on-classpath :prefix "leiningen")
+ (filter #(re-find #"^leiningen\.(?!core|main|util)[^\.]+$" (name %)))
+ (distinct)
+ (sort)))
+
+(defn suggestions [task]
+ (let [suggestions (into {} (for [t (tasks)
+ :let [n (.replaceAll (name t)
+ "leiningen." "")]]
+ [n (distance n task)]))
+ min (apply min (vals suggestions))]
+ (when (<= min 4)
+ (map first (filter #(= min (second %)) suggestions)))))
+
(defn ^:no-project-needed task-not-found [task & _]
- (abort (str task " is not a task. Use \"lein help\" to list all tasks.")))
+ (println (str "'" task "' is not a task. See 'lein help'."))
+ (when-let [suggestions (suggestions task)]
+ (println)
+ (println "Did you mean this?")
+ (doseq [suggestion suggestions]
+ (println " " suggestion)))
+ (abort))
;; TODO: got to be a cleaner way to do this, right?
(defn- drop-partial-args [pargs]
@@ -2,21 +2,12 @@
"Display a list of tasks or help for a given task."
(:require [clojure.string :as string]
[clojure.java.io :as io]
- [bultitude.core :as b]
[leiningen.core.main :as main]))
(def ^{:private true
:doc "Width of task name column in list of tasks produced by help task."}
task-name-column-width 20)
-(defn tasks
- "Return a list of symbols naming all visible tasks."
- []
- (->> (b/namespaces-on-classpath :prefix "leiningen")
- (filter #(re-find #"^leiningen\.(?!core|main|util)[^\.]+$" (name %)))
- (distinct)
- (sort)))
-
(defn- get-arglists [task]
(for [args (or (:help-arglists (meta task)) (:arglists (meta task)))]
(vec (remove #(= 'project %) args))))
@@ -103,7 +94,7 @@ deploying and copying info."
([project]
(println "Leiningen is a tool for working with Clojure projects.\n")
(println "Several tasks are available:")
- (doseq [task-ns (tasks)]
+ (doseq [task-ns (main/tasks)]
(println (help-summary-for task-ns)))
(println "\nRun lein help $TASK for details.")
(if-let [aliases (:aliases project)]
View
@@ -64,7 +64,3 @@ _lein_test() {
_lein_namespaces "test/"
}
-_lein_test!() {
- _lein_namespaces "test/"
-}
-

0 comments on commit e48486f

Please sign in to comment.