如何访问 leiningen 配置文件上的值? [英] How to access values on leiningen profiles?

查看:20
本文介绍了如何访问 leiningen 配置文件上的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 project.clj 中定义了两个配置文件,一个在本地,一个用于在 travis 上进行测试:

I've got a two profiles defined in project.clj, one locally, one for testing on travis:

:profiles {:dev {:dependencies [[midje "1.6.0"]
                                [mysql/mysql-connector-java "5.1.25"]]
                 :plugins [[lein-midje "3.1.3"]]
                 :user "root" :pass "root"}
           :travis {:user "travis" :pass ""}}

我希望能够在我的项目中访问 :user 和 :pass 值.这怎么办?

I'm hoping to be able to get access to the :user and :pass values in my projects. How can this be done?

更新:

我还希望能够使用 lein with-profile 命令...所以我的测试将有:

I also want to be able to use the lein with-profile command... so my tests would have:

lein with-profile dev test

-> 将使用root"、root"凭据

-> would use "root", "root" credentials

lein with-profile dev,travis test

-> 将使用 "travis", "" 凭据

-> would use "travis", "" credentials

推荐答案

如果您不需要 project.clj 中定义的值用于其他任何事情(IE,您可以自由选择表示)考虑环境.

If you don't need the values defined in project.clj for anything else (IE, you're free to choose the representation) consider Environ.

然后您可以在 project.clj 中定义以下内容

You can then define the following in your project.clj

:profiles {:dev {:env {:user "root" :pass "root"}}}

并读取值:

(use 'environ.core)

(def creds
  {:user (env :user)
   :pass (env :pass)})

这样做的好处是您还可以使用环境变量和系统属性来指定值.

This has the advantage that you can also specify the values using environment variables and system properties.

这篇关于如何访问 leiningen 配置文件上的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆