简体   繁体   English

我可以在REPL中的Lein项目中查找内容吗?

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

Say I have a vanilla project.clj like 说我有一个vanilla project.clj之类的

(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? lein repl ,我可以从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? 接下来的问题是我可以在project.clj中进一步使用项目图中的东西吗? Like if I wanted to pull that mailing list :name out and substitute it in as a :deb :maintainer? 就像我想拉那个邮件列表一样:命名并将其替换为: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? 我相信你可以告诉我,我对此很新,但是project.clj只是可执行的Clojure,不是吗? 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数据进行def ,并使用~包含它们

(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 这是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. 鉴于命名空间是leiningen.core.project ,地图应该在它之下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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