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

查看:98
本文介绍了如何访问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


b $ b

- >将使用travis,凭证

-> would use "travis", "" credentials

推荐答案

project.clj 中为其他任何内容定义(IE,您可以自由选择表示) Environ

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天全站免登陆