Apply CLI options later in process. Fixes 1843

This commit is contained in:
Thomas Reynolds 2016-03-20 16:44:20 -07:00
parent 7e42954258
commit aab7bac8a6
4 changed files with 19 additions and 17 deletions

View file

@ -22,12 +22,12 @@ module Middleman::Cli
if setting.default.is_a?(String) || setting.default.is_a?(NilClass) if setting.default.is_a?(String) || setting.default.is_a?(NilClass)
base.class_option setting.key, base.class_option setting.key,
type: :string, type: :string,
default: setting.default, default: :undefined,
desc: setting.description desc: setting.description
elsif setting.default.is_a?(TrueClass) || setting.default.is_a?(FalseClass) elsif setting.default.is_a?(TrueClass) || setting.default.is_a?(FalseClass)
base.class_option setting.key, base.class_option setting.key,
type: :boolean, type: :boolean,
default: setting.default, default: :undefined,
desc: setting.description desc: setting.description
end end
end end

View file

@ -63,14 +63,9 @@ module Middleman::Cli
@app = ::Middleman::Application.new do @app = ::Middleman::Application.new do
config[:mode] = :build config[:mode] = :build
config[:show_exceptions] = false config[:show_exceptions] = false
config[:cli_options] = cli_options.reduce({}) do |sum, (k, v)|
cli_options.each do |k, v| sum[k] = v unless v == :undefined
setting = config.setting(k.to_sym) sum
next unless setting
v = setting.options[:import].call(v) if setting.options[:import]
config[k.to_sym] = v
end end
end end

View file

@ -194,6 +194,8 @@ module Middleman
define_setting :skip_build_clean, proc { |p| [/\.git/].any? { |r| p =~ r } }, 'Whether some paths should not be removed during a clean build.' define_setting :skip_build_clean, proc { |p| [/\.git/].any? { |r| p =~ r } }, 'Whether some paths should not be removed during a clean build.'
define_setting :cli_options, {}, 'Options from the Command Line.'
define_setting :watcher_disable, false, 'If the Listen watcher should not run' define_setting :watcher_disable, false, 'If the Listen watcher should not run'
define_setting :watcher_force_polling, false, 'If the Listen watcher should run in polling mode' define_setting :watcher_force_polling, false, 'If the Listen watcher should run in polling mode'
define_setting :watcher_latency, nil, 'The Listen watcher latency' define_setting :watcher_latency, nil, 'The Listen watcher latency'
@ -281,6 +283,15 @@ module Middleman
# Run any `configure` blocks for the current mode. # Run any `configure` blocks for the current mode.
execute_callbacks([:configure, config[:mode]]) execute_callbacks([:configure, config[:mode]])
config[:cli_options].each do |k, v|
setting = config.setting(k.to_sym)
next unless setting
v = setting.options[:import].call(v) if setting.options[:import]
config[k.to_sym] = v
end
# Post parsing, pre-extension callback # Post parsing, pre-extension callback
execute_callbacks(:after_configuration_eval) execute_callbacks(:after_configuration_eval)

View file

@ -140,13 +140,9 @@ module Middleman
) )
app = ::Middleman::Application.new do app = ::Middleman::Application.new do
cli_options.each do |k, v| cli_options.reduce({}) do |sum, (k, v)|
setting = config.setting(k.to_sym) sum[k] = v unless v == :undefined
next unless setting sum
v = setting.options[:import].call(v) if setting.options[:import]
config[k.to_sym] = v
end end
ready do ready do