2014-01-02 19:34:08 -05:00
|
|
|
# Setup our load paths
|
|
|
|
libdir = File.expand_path(File.dirname(__FILE__))
|
|
|
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|
|
|
|
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'
|
2013-12-27 19:26:31 -05:00
|
|
|
require 'thor/group'
|
2011-07-27 00:06:10 -04:00
|
|
|
|
2011-12-21 14:03:45 -05:00
|
|
|
# CLI Module
|
2012-05-24 14:03:58 -04:00
|
|
|
module Middleman
|
|
|
|
|
|
|
|
module Cli
|
2012-08-13 18:39:06 -04:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
# The base task from which everything else etends
|
|
|
|
class Base < Thor
|
2012-07-16 20:24:13 -04:00
|
|
|
class << self
|
|
|
|
def start(*args)
|
|
|
|
# Change flag to a module
|
2013-12-27 19:26:31 -05:00
|
|
|
ARGV.unshift('help') if ARGV.delete('--help')
|
2012-07-16 20:24:13 -04:00
|
|
|
|
|
|
|
# Default command is server
|
2013-12-27 19:26:31 -05:00
|
|
|
if ARGV[0] != 'help' && (ARGV.length < 1 || ARGV.first.include?('-'))
|
|
|
|
ARGV.unshift('server')
|
2012-07-16 20:24:13 -04:00
|
|
|
end
|
2012-08-13 18:39:06 -04:00
|
|
|
|
2012-07-16 20:24:13 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2012-07-19 01:10:02 -04:00
|
|
|
|
2013-12-27 19:26:31 -05:00
|
|
|
desc 'version', 'Show version'
|
2012-05-24 14:03:58 -04:00
|
|
|
def version
|
|
|
|
require 'middleman-core/version'
|
|
|
|
say "Middleman #{Middleman::VERSION}"
|
|
|
|
end
|
2012-08-13 18:39:06 -04:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
# 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}")
|
2013-12-27 19:26:31 -05:00
|
|
|
klass.start(['-h', task].compact, :shell => self.shell)
|
2012-05-24 14:03:58 -04:00
|
|
|
else
|
|
|
|
list = []
|
2013-04-06 17:48:00 -04:00
|
|
|
Thor::Util.thor_classes_in(Middleman::Cli).each do |thor_class|
|
|
|
|
list += thor_class.printable_tasks(false)
|
2012-05-24 14:03:58 -04:00
|
|
|
end
|
|
|
|
list.sort!{ |a,b| a[0] <=> b[0] }
|
2012-08-13 18:39:06 -04:00
|
|
|
|
2013-12-27 19:26:31 -05:00
|
|
|
shell.say 'Tasks:'
|
2012-05-24 14:03:58 -04:00
|
|
|
shell.print_table(list, :ident => 2, :truncate => true)
|
|
|
|
shell.say
|
|
|
|
end
|
2011-12-21 16:23:43 -05:00
|
|
|
end
|
2012-08-13 18:39:06 -04:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
# Intercept missing methods and search subtasks for them
|
|
|
|
# @param [Symbol] meth
|
|
|
|
def method_missing(meth, *args)
|
|
|
|
meth = meth.to_s
|
2012-08-13 18:39:06 -04:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
if self.class.map.has_key?(meth)
|
|
|
|
meth = self.class.map[meth]
|
|
|
|
end
|
2012-08-13 18:39:06 -04:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
2012-08-13 18:39:06 -04:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
if klass.nil?
|
2013-12-27 19:26:31 -05:00
|
|
|
tasks_dir = File.join(Dir.pwd, 'tasks')
|
2012-01-16 17:55:08 -05:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
if File.exists?(tasks_dir)
|
2013-12-27 19:26:31 -05:00
|
|
|
Dir[File.join(tasks_dir, '**/*_task.rb')].each { |f| require f }
|
2012-05-24 14:03:58 -04:00
|
|
|
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
|
|
|
end
|
2012-01-16 17:55:08 -05:00
|
|
|
end
|
2012-08-13 18:39:06 -04:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
if klass.nil?
|
2012-09-28 02:20:04 -04:00
|
|
|
raise Thor::Error.new "There's no '#{meth}' command for Middleman. Try 'middleman help' for a list of commands."
|
2012-05-24 14:03:58 -04:00
|
|
|
else
|
|
|
|
args.unshift(task) if task
|
|
|
|
klass.start(args, :shell => self.shell)
|
|
|
|
end
|
2012-01-16 17:55:08 -05:00
|
|
|
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
|
2014-01-02 19:34:08 -05:00
|
|
|
require 'middleman-cli/init'
|
|
|
|
require 'middleman-cli/bundler'
|
|
|
|
require 'middleman-cli/extension'
|
|
|
|
require 'middleman-cli/server'
|
|
|
|
require 'middleman-cli/build'
|
|
|
|
require 'middleman-cli/console'
|