Add an experimental "console" CLI command.

The "console" command drops you into an IRB session in the context of the
Middleman application instance. You can look at configuration, poke around
at the sitemap and data, try out handlers (after calling self.current_path = "foo"), etc.
This commit is contained in:
Ben Hollis 2013-02-10 16:12:32 -08:00
parent 52c4677391
commit 2a5513dcc9
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