fix errant MM bootup during CLI. Make an autodiscoverable tasks/ directory

This commit is contained in:
Thomas Reynolds 2012-01-16 14:55:08 -08:00
parent aeb9d10b25
commit d1f0e6f616
5 changed files with 30 additions and 17 deletions

View file

@ -1,10 +0,0 @@
class HelloWorld < Thor
default_task :say_hi
desc "hello", "Say hello"
def say_hi
puts "Hello World"
end
end
Middleman::Cli::Base.register(HelloWorld, :hello, "hello", "Say hello")

View file

@ -0,0 +1,6 @@
class Hello < Thor
desc "hello", "Say hello"
def hello
puts "Hello World"
end
end

View file

@ -45,10 +45,24 @@ module Middleman::Cli
end end
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}") klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
if klass.nil?
tasks_dir = File.join(Dir.pwd, "tasks")
if File.exists?(tasks_dir)
Dir[File.join(tasks_dir, "**/*_task.rb")].each { |f| require f }
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
end
end
if klass.nil?
super
else
args.unshift(task) if task args.unshift(task) if task
klass.start(args, :shell => self.shell) klass.start(args, :shell => self.shell)
end end
end end
end
end end
# Include the core CLI items # Include the core CLI items

View file

@ -85,10 +85,12 @@ module Middleman::Cli
sess sess
end end
end end
end
# Set the root path to the Middleman::Base's root # Set the root path to the Middleman::Base's root
source_root(shared_instance.root) def source_root
shared_instance.root
end
end
# Ignore following method # Ignore following method
desc "", "", :hide => true desc "", "", :hide => true

View file

@ -70,12 +70,13 @@ module Middleman
# @return [void] # @return [void]
def bootup def bootup
env = (@options[:environment] || "development").to_sym env = (@options[:environment] || "development").to_sym
is_logging = @options.has_key?(:debug) && (@options[:debug] == "true") is_logging = @options.has_key?(:debug) && @options[:debug]
app = ::Middleman.server.inst do app = ::Middleman.server.inst do
set :environment, env set :environment, env
set :logging, is_logging set :logging, is_logging
end end
$stderr.puts "Is logging?: #{is_logging}"
app_rack = app.class.to_rack_app app_rack = app.class.to_rack_app
opts = @options.dup opts = @options.dup