Expose all config options to CLIs. Helps with #1829

This commit is contained in:
Thomas Reynolds 2016-03-12 13:55:25 -08:00
parent d624dc4601
commit 1f3bf47e3c
9 changed files with 78 additions and 70 deletions

View file

@ -1,3 +1,5 @@
require 'middleman-core/application'
# CLI Module
module Middleman::Cli
# The CLI Build class
@ -8,8 +10,7 @@ module Middleman::Cli
class_option :environment,
aliases: '-e',
default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'production',
desc: 'The environment Middleman will run under'
default: :production
class_option :clean,
type: :boolean,
default: true,
@ -36,6 +37,8 @@ module Middleman::Cli
default: false,
desc: 'Generate profiling report for the build'
Middleman::Cli.import_config(self)
# Core build Thor command
# @return [void]
def build
@ -48,19 +51,27 @@ module Middleman::Cli
require 'middleman-core/builder'
require 'fileutils'
env = options['environment'].to_sym
verbose = options['verbose'] ? 0 : 1
instrument = options['instrument']
builder = nil
cli_options = options
::Middleman::Logger.singleton(verbose, instrument)
::Middleman::Util.instrument 'builder.setup' do
@app = ::Middleman::Application.new do
config[:mode] = :build
config[:environment] = env
config[:show_exceptions] = false
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
end
builder = Middleman::Builder.new(@app,

View file

@ -5,25 +5,13 @@ module Middleman::Cli
check_unknown_options!
class_option :environment,
aliases: '-e',
default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
desc: 'The environment Middleman will run under'
aliases: '-e'
class_option :port,
aliases: '-p',
desc: 'The port Middleman will listen on'
aliases: '-p'
class_option :server_name,
aliases: '-s',
desc: 'The server name Middleman will use'
aliases: '-s'
class_option :bind_address,
aliases: '-b',
desc: 'The bind address Middleman will listen on'
class_option :https,
type: :boolean,
desc: 'Serve the preview server over SSL/TLS'
class_option :ssl_certificate,
desc: 'Path to an X.509 certificate to use for the preview server'
class_option :ssl_private_key,
desc: "Path to an RSA private key for the preview server's certificate"
aliases: '-b'
class_option :verbose,
type: :boolean,
default: false,
@ -32,29 +20,18 @@ module Middleman::Cli
type: :string,
default: false,
desc: 'Print instrument messages'
class_option :disable_watcher,
type: :boolean,
default: false,
desc: 'Disable the file change and delete watcher process'
class_option :profile,
type: :boolean,
default: false,
desc: 'Generate profiling report for server startup'
class_option :force_polling,
type: :boolean,
default: false,
desc: 'Force file watcher into polling mode'
class_option :latency,
type: :numeric,
aliases: '-l',
default: 0.5,
desc: 'Set file watcher latency, in seconds'
class_option :daemon,
type: :boolean,
aliases: '-d',
default: false,
desc: 'Daemonize preview server'
Middleman::Cli.import_config(self)
# Start the server
def server
require 'middleman-core'
@ -66,24 +43,14 @@ module Middleman::Cli
end
params = {
port: options['port'],
bind_address: options['bind_address'],
https: options['https'],
server_name: options['server_name'],
ssl_certificate: options['ssl_certificate'],
ssl_private_key: options['ssl_private_key'],
environment: options['environment'],
debug: options['verbose'],
instrumenting: options['instrument'],
disable_watcher: options['disable_watcher'],
reload_paths: options['reload_paths'],
force_polling: options['force_polling'],
latency: options['latency'],
daemon: options['daemon']
}
puts '== The Middleman is loading'
::Middleman::PreviewServer.start(params)
::Middleman::PreviewServer.start(params, options)
end
# Add to CLI