Merge pull request #775 from bhollis/console

Add an experimental "console" CLI command.
This commit is contained in:
Ben Hollis 2013-02-14 08:51:48 -08:00
commit ff971dd327
2 changed files with 47 additions and 0 deletions

View file

@ -87,3 +87,4 @@ require "middleman-core/cli/bundler"
require "middleman-core/cli/extension" require "middleman-core/cli/extension"
require "middleman-core/cli/server" require "middleman-core/cli/server"
require "middleman-core/cli/build" require "middleman-core/cli/build"
require "middleman-core/cli/console"

View file

@ -0,0 +1,46 @@
# CLI Module
module Middleman::Cli
# A thor task for creating new projects
class Console < Thor
include Thor::Actions
check_unknown_options!
namespace :console
desc "console [options]", "Start an interactive console in the context of your Middleman application"
method_option :environment,
:aliases => "-e",
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
:desc => "The environment Middleman will run under"
method_option :verbose,
:type => :boolean,
:default => false,
:desc => 'Print debug messages'
def console
require "middleman-core"
require "irb"
opts = {
:environment => options['environment'],
:debug => options['verbose']
}
@app =::Middleman::Application.server.inst do
if opts[:environment]
set :environment, opts[:environment].to_sym
end
logger(opts[:debug] ? 0 : 1, opts[:instrumenting] || false)
end
# TODO: get file watcher / reload! working in console
IRB.setup nil
IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
require 'irb/ext/multi-irb'
IRB.irb nil, @app
end
end
end