Skip to content

Commit

Permalink
Grabbing the cloc version from the project :plugins vector and fixing…
Browse files Browse the repository at this point in the history
… the command line args.
  • Loading branch information
jaley committed Aug 28, 2013
1 parent 451c866 commit 7512d9c
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/clj/leiningen/cloc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@
"Leiningen plugin to start the cloc web server locally."
(:require [leiningen.core.classpath :as cp]
[leiningen.core.eval :as eval]
[leiningen.core.project :as proj]
[cemerick.pomegranate.aether :as aether]))

(def dummy-project
{:dependencies [['cloc "0.1.0-SNAPSHOT"]]})
(defn dummy-project
"Create a barebones project with the configured cloc version as
its only dependency."
[project]
(if-let [cloc-vec (first
(drop-while
(complement
(fn [v] (= (first v) 'cloc/cloc)))
(:plugins project)))]
{:dependencies [cloc-vec]}
(throw (Exception. (str "Cloc should be in your :plugins vector, "
"either in your ~/.lein/profiles.clj or in "
"the project itself.")))))

(defn- try-parse
"Try to convert v to integer, then bool, else string."
Expand All @@ -18,23 +30,26 @@

(defn cloc
"Start the cloc doc server locally, serving API docs for
your code and all your dependencies. Accepts ring configuration
map keyword and value arguments. Most useful ones will be:
your code and all your dependencies. Accepts ring configuration
map key and value arguments. Keys should be strings, so omit colons.
Most useful ones will be:
- :host -- host name to listen on
- :port -- port to listen for connections on"
- host -- host name to listen on (default: localhost)
- port -- port to listen for connections on (default: 1337)"
[project & args]
(assert (even? (count args))
"Number of args should be even - only key-value pairs supported.")
(let [opts (merge
{:port 1337}
(reduce (fn [m [k v ]] (assoc m (keyword k) (try-parse v)))
{}
(partition 2 args))
{:port 1337 :join? true})
{:join? true})
jars (mapv str
(filter (fn [f] (re-find #"\.jar$" (.getName f)))
(aether/dependency-files
(cp/dependency-hierarchy :dependencies project))))]
(eval/eval-in-project dummy-project
(println opts)
(eval/eval-in-project (dummy-project project)
`(cloc.core/main ~opts ~jars)
'(require 'cloc.core))))

0 comments on commit 7512d9c

Please sign in to comment.