2011-12-29 01:52:51 -05:00
|
|
|
# Require thor since that's what the who CLI is built around
|
2011-07-27 00:06:10 -04:00
|
|
|
require 'thor'
|
2011-12-21 14:03:45 -05:00
|
|
|
require "thor/group"
|
2011-07-27 00:06:10 -04:00
|
|
|
|
2011-12-21 14:03:45 -05:00
|
|
|
# CLI Module
|
2011-12-21 15:13:28 -05:00
|
|
|
module Middleman::Cli
|
2011-12-21 14:03:45 -05:00
|
|
|
|
2012-04-14 16:51:02 -04:00
|
|
|
module Cli
|
|
|
|
autoload :Build, "middleman-core/cli/build"
|
|
|
|
autoload :Init, "middleman-core/cli/init"
|
|
|
|
autoload :Server, "middleman-core/cli/server"
|
|
|
|
end
|
|
|
|
|
2011-12-29 01:52:51 -05:00
|
|
|
# The base task from which everything else etends
|
2011-12-21 14:03:45 -05:00
|
|
|
class Base < Thor
|
2011-12-29 01:52:51 -05:00
|
|
|
|
2011-11-10 17:35:27 -05:00
|
|
|
desc "version", "Show version"
|
2011-08-03 17:43:02 -04:00
|
|
|
def version
|
2011-12-29 18:09:51 -05:00
|
|
|
require 'middleman-core/version'
|
2011-12-29 22:04:39 -05:00
|
|
|
say "Middleman #{Middleman::VERSION}"
|
2011-08-03 17:43:02 -04:00
|
|
|
end
|
|
|
|
|
2011-12-29 01:52:51 -05:00
|
|
|
# Override the Thor help method to find help for subtasks
|
|
|
|
# @param [Symbol, String, nil] meth
|
|
|
|
# @param [Boolean] subcommand
|
|
|
|
# @return [void]
|
2011-12-21 16:23:43 -05:00
|
|
|
def help(meth = nil, subcommand = false)
|
|
|
|
if meth && !self.respond_to?(meth)
|
|
|
|
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
|
|
|
klass.start(["-h", task].compact, :shell => self.shell)
|
|
|
|
else
|
|
|
|
list = []
|
|
|
|
Thor::Util.thor_classes_in(Middleman::Cli).each do |klass|
|
|
|
|
list += klass.printable_tasks(false)
|
|
|
|
end
|
|
|
|
list.sort!{ |a,b| a[0] <=> b[0] }
|
|
|
|
|
|
|
|
shell.say "Tasks:"
|
|
|
|
shell.print_table(list, :ident => 2, :truncate => true)
|
|
|
|
shell.say
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-29 01:52:51 -05:00
|
|
|
# Intercept missing methods and search subtasks for them
|
|
|
|
# @param [Symbol] meth
|
2011-12-21 15:13:28 -05:00
|
|
|
def method_missing(meth, *args)
|
|
|
|
meth = meth.to_s
|
|
|
|
|
|
|
|
if self.class.map.has_key?(meth)
|
|
|
|
meth = self.class.map[meth]
|
|
|
|
end
|
|
|
|
|
|
|
|
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
2012-01-16 17:55:08 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
klass.start(args, :shell => self.shell)
|
|
|
|
end
|
2011-12-21 15:13:28 -05:00
|
|
|
end
|
2011-07-27 00:06:10 -04:00
|
|
|
end
|
2011-12-14 02:58:34 -05:00
|
|
|
end
|
2011-12-21 14:03:45 -05:00
|
|
|
|
2011-12-29 01:52:51 -05:00
|
|
|
# Include the core CLI items
|
2011-12-29 18:09:51 -05:00
|
|
|
require "middleman-core/cli/init"
|
|
|
|
require "middleman-core/cli/server"
|
|
|
|
require "middleman-core/cli/build"
|