Permalink
Browse files

Make search and update-repo tasks work outside a project.

Leiningen 1.3+ will inspect the arglist of the task, and if it doesn't
see one named "project", it will not pass in a project map. This
allows it to be used outside the context of a project. But we also
must accept it in order to maintain 1.2 compatibility.
  • Loading branch information...
1 parent b5f3c0c commit c3ba38f4408d75f5c09b1fddccb23f9bdf72a826 @technomancy technomancy committed with Aug 19, 2010
Showing with 16 additions and 12 deletions.
  1. +15 −10 src/leiningen/search.clj
  2. +1 −2 src/leiningen/update_repo.clj
View
@@ -5,13 +5,18 @@
(:import java.io.File))
-(defn search [project what & args]
- (let [show-versions (= "-v" what)
- what (if show-versions (first args) what)]
- (if (.exists (File. (str *lein-dir* "/clojars")))
- (let [m (search-clojar what)]
- (println "Results for " what ":")
- (if show-versions
- (println (str-join "\n" (map (fn [{versions :versions artifact-id :artifact-id group-id :group-id}] (str (clojars-artifact-name group-id artifact-id) ": " (str-join ", " versions))) m)))
- (println (str-join "\n" (map (fn [{description :description artifact-id :artifact-id group-id :group-id}] (format "%-40s - %s" (clojars-artifact-name group-id artifact-id) (re-sub #"\n\s*" " " (or description "No description given")))) m)))))
- (println "No repo index found, please run lein update first."))))
+(defn search [what & args]
+ (if (map? what)
+ ;; To be backwards-compatible with Leiningen 1.2 and prior, we
+ ;; must accept and discard a project argument. Current Leiningen (1.3+)
+ ;; inspects the arg list and only passes in the project if needed.
+ (apply search args)
+ (let [show-versions (= "-v" what)
+ what (if show-versions (first args) what)]
+ (if (.exists (File. (str *lein-dir* "/clojars")))
+ (let [m (search-clojar what)]
+ (println "Results for " what ":")
+ (if show-versions
+ (println (str-join "\n" (map (fn [{versions :versions artifact-id :artifact-id group-id :group-id}] (str (clojars-artifact-name group-id artifact-id) ": " (str-join ", " versions))) m)))
+ (println (str-join "\n" (map (fn [{description :description artifact-id :artifact-id group-id :group-id}] (format "%-40s - %s" (clojars-artifact-name group-id artifact-id) (re-sub #"\n\s*" " " (or description "No description given")))) m)))))
+ (println "No repo index found, please run lein update first.")))))
@@ -2,7 +2,6 @@
"Updates the clojars.org repositories index."
(:use lein-search.core))
-
-(defn update-repo [project & args]
+(defn update-repo [& _]
(println "Getting the list of packages on clojars.org ...")
(write-clojars-cache))

0 comments on commit c3ba38f

Please sign in to comment.