/
project_options.rb
45 lines (39 loc) · 1.31 KB
/
project_options.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Tomo
class CLI
module ProjectOptions
def self.included(mod)
mod.class_eval do
option :project, "-c, --config PATH", "Location of project config (default: #{DEFAULT_CONFIG_PATH})"
end
end
private
def configure_runtime(options, strict: true)
config = load_configuration(options)
env = options[:environment]
env = config.environments.keys.first if env.nil? && !strict
config = config.for_environment(env)
config.settings.merge!(settings_from_env)
config.settings.merge!(settings_from_options(options))
config.build_runtime
end
def load_configuration(options)
path = options[:project] || DEFAULT_CONFIG_PATH
@config_cache ||= {}
@config_cache[path] ||= Configuration.from_config_rb(path)
end
def settings_from_options(options)
options.all(:settings).each_with_object({}) do |arg, settings|
name, value = arg.split("=", 2)
settings[name.to_sym] = value
end
end
def settings_from_env
ENV.each_with_object({}) do |(key, value), result|
setting_name = key[/^TOMO_(\w+)$/i, 1]&.downcase
next if setting_name.nil?
result[setting_name.to_sym] = value
end
end
end
end
end