简体   繁体   中英

Can I lookup things within a Lein Project in the REPL?

Say I have a vanilla project.clj like

(defproject myservice "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :mailing-list {:name "myservice@example.com" :post "myservice@climate.com"}
  :license {:name "Eclipse Public License"
            :url  "http://www.eclipse.org/legal/epl-v10.html"}

  :dependencies [[org.clojure/clojure "1.6.0"]
                 [ring/ring-core "1.4.0"]
                 [ring/ring-jetty-adapter "1.4.0"]
                 [compojure "1.4.0"]
                 [ring/ring-defaults "0.1.5"]
                 [org.clojure/tools.logging "0.3.1"]
                 [clj-http "2.0.0"]]

  :plugins [[lein-ring "0.9.7"]]

  :ring {:handler myservice.core/standalone-app
         :port 3000}
  :profiles {
             :uberjar {:ring {:handler myservice.core/app}}}
  )

In a lein repl , can I lookup values from the project.clj? How? Of course my blind hack didn't work?

user=> (:mailing-list project)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: project in this context, compiling:(/private/var/folders/1g/fnytl2x93sx6hp2f1rsf4h1r5xtqv_/T/form-init6671981825845237047.clj:1:1)

The follow on question is can I use stuff from the project map further on in the project.clj? Like if I wanted to pull that mailing list :name out and substitute it in as a :deb :maintainer?

:deb 
  {:toDir "target"
   :package "mysevice"
   :maintainer {:name "Meeples", :email "myservice@example.com"}
   ...
  }

I'm sure you can tell, I'm kind-of new to this, but the project.clj is just executable Clojure, no? If I knew the name of the project's map, I should be able to query it, right?

You can def data as you usually would and include them using ~

(def mailing-list {:name "myservice@example.com" :post "myservice@climate.com"})

(defproject myservice "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :mailing-list ~mailing-list
  :license {:name "Eclipse Public License"
            :url  "http://www.eclipse.org/legal/epl-v10.html"}

  :dependencies [[org.clojure/clojure "1.6.0"]
                 [ring/ring-core "1.4.0"]
                 [ring/ring-jetty-adapter "1.4.0"]
                 [compojure "1.4.0"]
                 [ring/ring-defaults "0.1.5"]
                 [org.clojure/tools.logging "0.3.1"]
                 [clj-http "2.0.0"]]

  :plugins [[lein-ring "0.9.7"]]

  :ring {:handler myservice.core/standalone-app
         :port 3000}
  :profiles {
             :uberjar {:ring {:handler myservice.core/app}}}
  :deb {
        :toDir "target"
        :package "mysevice"
        :maintainer {:name "Meeples", :email (:name ~mailing-list)}})

This is the relevant line in leiningen : https://github.com/technomancy/leiningen/blob/b29b2ea41b6d177a8a57493b979164eab0931e4d/leiningen-core/src/leiningen/core/project.clj#L405

Given the namespace is leiningen.core.project , the map should be under it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM