我正在用ruby构建一个cli工具,我需要从不同的来源获取配置:环境变量、dotfile、参数或硬编码的值。(具有优先权制度)
在node.js中,我会使用nconf.js来完成这个任务。
在红宝石中是否有一些配置宝石可以做这样的事情?
发布于 2021-02-25 02:53:28
实际的答案是:
更新:2020年-02-26
https://github.com/infochimps-labs/configliere
引用作者的话:
愿意和这五个家庭坐下来。从(根据您的选择)获取设置:
简单地说。就像nconf一样。
require 'configliere'
Settings.use :commandline
Settings({
:dest_time => '11-05-1955',
:fluxcapacitor => {
:speed => 88,
},
:delorean => {
:power_source => 'plutonium',
:roads_needed => true,
},
:username => 'marty',
:password => '',
})
#set a value to possibly also come from env
Settings.define :dest_time, :env_var => 'DEST_TIME'
Settings.read "#{__dir__}/config.yml"
Settings.read "#{Dir.pwd()}/config.yml"
Settings.resolve!旧的答案:
https://github.com/rubyconfig/config#working-with-environment-variables
它不执行argv,但它允许您对各种yaml文件进行分层,然后使用ENV覆盖,就像nconf允许您一样。
https://stackoverflow.com/questions/33651553
复制相似问题