Permalink
Browse files

Update the repo index if it doesn't exist when you search.

  • Loading branch information...
technomancy authored and Licenser committed Aug 19, 2010
1 parent 23b843c commit e3c10b1788f849a70dc002dcca84b0cbf30fff4d
Showing with 16 additions and 15 deletions.
  1. +2 −2 src/lein_search/core.clj
  2. +14 −13 src/leiningen/search.clj
View
@@ -4,7 +4,7 @@
(:require [clojure.zip :as zip])
(:import (java.io File PushbackReader) java.util.zip.GZIPInputStream java.net.URL))
-
+;; TODO: check to see if leiningen.core/home-dir is defined; use it if so.
(def *lein-dir* (str (System/getProperty "user.home") "/.lein"))
;;; User input functions
@@ -188,4 +188,4 @@ the supplied zip move function each time"
article-id
(str group-id "/" article-id)))
([{artifact-id :artifact-id group-id :group-id}]
- (clojars-artifact-name group-id artifact-id)))
+ (clojars-artifact-name group-id artifact-id)))
View
@@ -2,7 +2,8 @@
"Searches the indexed clojars.org repository. Giving -v as first argument
prints the versions instead of the description."
(:use [clojure.contrib.str-utils :only (str-join re-sub)]
- lein-search.core)
+ lein-search.core
+ leiningen.update-repo)
(:import java.io.File))
(defn search [what & args]
@@ -14,16 +15,16 @@ prints the versions instead of the description."
(let [show-versions (= "-v" what)
what (if show-versions (first args) what)]
(if (.exists (File. (str *lein-dir* "/clojars")))
- (let [m (search-clojar what)]
+ (let [results (search-clojar what)]
(println (format "Results for %s:" what))
- (if show-versions
- (doseq [{:keys [versions artifact-id group-id]} m
- :let [name (clojars-artifact-name group-id artifact-id)
- versions-string (str-join ", " versions)]]
- (println (format "%s: %s" name versions-string)))
- (doseq [{:keys [description artifact-id group-id]} m
- :let [name (clojars-artifact-name group-id artifact-id)
- desc (or description "No description given")
- desc (re-sub #"\n\s*" " " desc)]]
- (println (format "%-40s - %s" name desc)))))
- (println "No repo index found, please run lein update first.")))))
+ (doseq [{:keys [description versions artifact-id group-id]} results
+ :let [name (clojars-artifact-name group-id artifact-id)
+ versions-string (str-join ", " versions)
+ description (or description "No description given")
+ desc (re-sub #"\n\s*" " " description)]]
+ (println (if show-versions
+ (format "%s: %s" name versions-string)
+ (format "%-40s - %s" name desc)))))
+ ;; If there's no index found, fetch it and try again.
+ (do (update-repo)
+ (apply search what args))))))

0 comments on commit e3c10b1

Please sign in to comment.