1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/middleman-core/lib/middleman-core/cli.rb

76 lines
2.2 KiB
Ruby
Raw Normal View History

2011-12-29 01:52:51 -05:00
# Require thor since that's what the who CLI is built around
require 'thor'
require "thor/group"
# CLI Module
module Middleman
module Cli
2011-12-29 01:52:51 -05:00
# The base task from which everything else etends
class Base < Thor
2011-08-03 17:43:02 -04:00
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] }
2011-12-21 16:23:43 -05:00
shell.say "Tasks:"
shell.print_table(list, :ident => 2, :truncate => true)
shell.say
end
2011-12-21 16:23:43 -05:00
end
# Intercept missing methods and search subtasks for them
# @param [Symbol] meth
def method_missing(meth, *args)
meth = meth.to_s
2011-12-21 15:13:28 -05:00
if self.class.map.has_key?(meth)
meth = self.class.map[meth]
end
2011-12-21 15:13:28 -05:00
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
2011-12-21 15:13:28 -05:00
end
end
end
2011-12-29 01:52:51 -05:00
# Include the core CLI items
require "middleman-core/cli/init"
2012-05-10 17:47:29 -04:00
require "middleman-core/cli/bundler"
2012-05-02 18:59:36 -04:00
require "middleman-core/cli/extension"
require "middleman-core/cli/server"
require "middleman-core/cli/build"