scala 如何在命令行上覆盖类型安全配置列表值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16202501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 05:13:26  来源:igfitidea点击:

How can I override a typesafe config list value on the command line?

javascalaconfigtypesafe

提问by Michael Frank

I have an application.conffile with a structure like the following:

我有application.conf一个结构如下的文件:

poller {
  datacenters = []
}

I would like to override "datacenters"on the command line.

我想"datacenters"在命令行上覆盖。

For other configuration keys whose values are simple types (strings, numbers) I can override using -Dpath.to.config.value=<value>, and this works fine.

对于值为简单类型(字符串、数字)的其他配置键,我可以使用 覆盖-Dpath.to.config.value=<value>,这很好用。

However, I can't seem to find a way to do this for lists. In the example above, I tried to set "datacenters"to ["SJC", "IAD"]like so: -Dpoller.datacenters="['SJC', 'IAD']", but I get an exception that the key value is a string, not a list.

但是,我似乎找不到对list执行此操作的方法。在上面的例子中,我试图设置"datacenters"["SJC", "IAD"]like so: -Dpoller.datacenters="['SJC', 'IAD']",但我得到一个例外,即键值是一个字符串,而不是一个列表。

Is there a way to signal to the typesafe config library that this value is a list?

有没有办法向类型安全配置库发出这个值是一个列表的信号?

回答by Patrik Nordwall

An alternative syntax is implemented in version 1.0.1 for this:

版本 1.0.1 中为此实现了另一种语法:

-Dpoller.datacenters.0=SJC -Dpoller.datacenters.1=IAD

回答by Alois Cochard

I had the same issue some weeks ago, and finally dived into the source code to understand what's going on:

几周前我遇到了同样的问题,最后深入研究源代码以了解发生了什么:

  • This feature is not implemented, it's not possible to define a list using command line argument
  • 此功能未实现,无法使用命令行参数定义列表

Fixing it wouldn't be that hard, but someone need to take time to do it.

修复它不会那么难,但需要有人花时间去做。