Fix custom commands for Ruby 1.9.x

This commit is contained in:
Thomas Reynolds 2011-12-21 12:13:28 -08:00
parent 21388f2103
commit 98b2b293c1
9 changed files with 67 additions and 34 deletions

View file

@ -50,7 +50,7 @@ module Middleman
def start_cli!
require 'middleman'
Middleman::CLI::Base.start
Middleman::Cli::Base.start
end
end
end

View file

@ -45,3 +45,8 @@ Feature: Builder
Scenario: Build with errors
Given a built app at "build-with-errors-app"
Then the exit status should be 1
Scenario: Build alias (b)
Given a fixture app "test-app"
When I run `middleman b`
Then was successfully built

View file

@ -15,6 +15,18 @@ Feature: Middleman CLI
| index.html.erb |
| layout.erb |
| stylesheets/site.css.scss |
Scenario: Create a new project (alias i)
When I run `middleman i MY_PROJECT`
Then a directory named "MY_PROJECT" should exist
Scenario: Create a new project (alias i)
When I run `middleman new MY_PROJECT`
Then a directory named "MY_PROJECT" should exist
Scenario: Create a new project (alias i)
When I run `middleman n MY_PROJECT`
Then a directory named "MY_PROJECT" should exist
Scenario: Create a new project with Rack
When I run `middleman init MY_PROJECT --rack`

View file

@ -7,4 +7,4 @@ class HelloWorld < Thor
end
end
Middleman::CLI::Base.register(HelloWorld, :hello, "hello", "Say hello")
Middleman::Cli::Base.register(HelloWorld, :hello, "hello", "Say hello")

View file

@ -15,10 +15,10 @@ module Middleman
autoload :Templates, "middleman/templates"
autoload :Guard, "middleman/guard"
module CLI
module Cli
autoload :Base, "middleman/cli"
autoload :Build, "middleman/cli/build"
autoload :Templates, "middleman/cli/templates"
autoload :Init, "middleman/cli/init"
autoload :Server, "middleman/cli/server"
end

View file

@ -2,7 +2,7 @@ require 'thor'
require "thor/group"
# CLI Module
module Middleman::CLI
module Middleman::Cli
class Base < Thor
include Thor::Actions
@ -22,6 +22,19 @@ module Middleman::CLI
say "Middleman #{Middleman::VERSION}"
end
def method_missing(meth, *args)
meth = meth.to_s
if self.class.map.has_key?(meth)
meth = self.class.map[meth]
end
# initialize_thorfiles(meth)
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
args.unshift(task) if task
klass.start(args, :shell => self.shell)
end
private
def help_check
@ -31,6 +44,6 @@ module Middleman::CLI
end
end
require "middleman/cli/templates"
require "middleman/cli/init"
require "middleman/cli/server"
require "middleman/cli/build"

View file

@ -1,23 +1,25 @@
require "rack"
require "rack/test"
module Middleman::CLI
class Build < Thor::Group
module Middleman::Cli
class Build < Thor
include Thor::Actions
check_unknown_options!
desc "build [options]"
class_option :relative,
namespace :build
desc "build [options]", "Builds the static site for deployment"
method_option :relative,
:type => :boolean,
:aliases => "-r",
:default => false,
:desc => 'Force relative urls'
class_option :clean,
method_option :clean,
:type => :boolean,
:aliases => "-c",
:default => false,
:desc => 'Removes orpahand files or directories from build'
class_option :glob,
method_option :glob,
:type => :string,
:aliases => "-g",
:default => nil,
@ -185,6 +187,5 @@ module Middleman::CLI
end
end
Base.register(Build, :build, "build [options]", "Builds the static site for deployment")
Base.map({ "b" => "build" })
end

View file

@ -1,32 +1,34 @@
module Middleman::CLI
class Templates < Thor::Group
module Middleman::Cli
class Init < Thor
check_unknown_options!
desc "init NAME [options]"
namespace :init
desc "init NAME [options]", "Create new project NAME"
available_templates = ::Middleman::Templates.registered.keys.join(", ")
argument :name
class_option "template",
# argument :name
method_option "template",
:aliases => "-T",
:default => "default",
:desc => "Use a project template: #{available_templates}"
class_option "css_dir",
method_option "css_dir",
:default => "stylesheets",
:desc => 'The path to the css files'
class_option "js_dir",
method_option "js_dir",
:default => "javascripts",
:desc => 'The path to the javascript files'
class_option "images_dir",
method_option "images_dir",
:default => "images",
:desc => 'The path to the image files'
class_option "rack",
method_option "rack",
:type => :boolean,
:default => false,
:desc => 'Include a config.ru file'
class_option "bundler",
method_option "bundler",
:type => :boolean,
:default => false,
:desc => 'Create a Gemfile and use Bundler to manage gems'
def init
def init(name)
key = options[:template].to_sym
unless ::Middleman::Templates.registered.has_key?(key)
raise Thor::Error.new "Unknown project template '#{key}'"
@ -37,7 +39,6 @@ module Middleman::CLI
end
end
Base.register(Templates, :init, "init NAME [options]", "Create new project NAME")
Base.map({
"i" => "init",
"new" => "init",

View file

@ -1,23 +1,25 @@
module Middleman::CLI
class Server < Thor::Group
module Middleman::Cli
class Server < Thor
check_unknown_options!
desc "server [options]"
class_option "environment",
namespace :server
desc "server [options]", "Start the preview server"
method_option "environment",
:aliases => "-e",
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
:desc => "The environment Middleman will run under"
class_option :host,
method_option :host,
:type => :string,
:aliases => "-h",
# :required => true,
:default => "0.0.0.0",
:desc => "Bind to HOST address"
class_option "port",
method_option "port",
:aliases => "-p",
:default => "4567",
:desc => "The port Middleman will listen on"
class_option "debug",
method_option "debug",
:type => :boolean,
:default => false,
:desc => 'Print debug messages'
@ -34,7 +36,6 @@ module Middleman::CLI
end
end
Base.register(Server, :server, "server [options]", "Start the preview server")
Base.map({ "s" => "server" })
Base.default_task :server
end