Re-arrange CLI loads for hopefully faster startup time
This commit is contained in:
parent
fffa80a987
commit
94c5f32853
5 changed files with 98 additions and 96 deletions
|
@ -2,64 +2,77 @@
|
|||
require 'thor'
|
||||
require "thor/group"
|
||||
|
||||
# CLI Module
|
||||
module Middleman::Cli
|
||||
|
||||
# The base task from which everything else etends
|
||||
class Base < Thor
|
||||
|
||||
desc "version", "Show version"
|
||||
def version
|
||||
require 'middleman-core/version'
|
||||
say "Middleman #{Middleman::VERSION}"
|
||||
end
|
||||
|
||||
# Override the Thor help method to find help for subtasks
|
||||
# @param [Symbol, String, nil] meth
|
||||
# @param [Boolean] subcommand
|
||||
# @return [void]
|
||||
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
|
||||
|
||||
# Intercept missing methods and search subtasks for them
|
||||
# @param [Symbol] meth
|
||||
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}")
|
||||
|
||||
if klass.nil?
|
||||
tasks_dir = File.join(Dir.pwd, "tasks")
|
||||
# Core Pathname library used for traversal
|
||||
require "pathname"
|
||||
|
||||
if File.exists?(tasks_dir)
|
||||
Dir[File.join(tasks_dir, "**/*_task.rb")].each { |f| require f }
|
||||
# CLI Module
|
||||
module Middleman
|
||||
|
||||
# Recursive method to find config.rb
|
||||
def self.locate_root(cwd = Pathname.new(Dir.pwd))
|
||||
return cwd.to_s if File.exists?(File.join(cwd, 'config.rb'))
|
||||
return false if cwd.root?
|
||||
locate_root(cwd.parent)
|
||||
end
|
||||
|
||||
module Cli
|
||||
|
||||
# The base task from which everything else etends
|
||||
class Base < Thor
|
||||
|
||||
desc "version", "Show version"
|
||||
def version
|
||||
require 'middleman-core/version'
|
||||
say "Middleman #{Middleman::VERSION}"
|
||||
end
|
||||
|
||||
# Override the Thor help method to find help for subtasks
|
||||
# @param [Symbol, String, nil] meth
|
||||
# @param [Boolean] subcommand
|
||||
# @return [void]
|
||||
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
|
||||
|
||||
# Intercept missing methods and search subtasks for them
|
||||
# @param [Symbol] meth
|
||||
def method_missing(meth, *args)
|
||||
meth = meth.to_s
|
||||
|
||||
if klass.nil?
|
||||
super
|
||||
else
|
||||
args.unshift(task) if task
|
||||
klass.start(args, :shell => self.shell)
|
||||
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}")
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue