Permalink
Browse files

Merge pull request #45 from binaryactivist/error

error
  • Loading branch information...
2 parents 3f8a4f1 + 761b109 commit 0f3262bf72fff6ce82159f7eb5a7b2eca358beda Dave Thompson committed May 2, 2012
Showing with 67 additions and 28 deletions.
  1. +12 −3 features/bookshop.feature
  2. +6 −2 lib/bookshop.rb
  3. +22 −0 lib/bookshop/error.rb
  4. +27 −23 lib/bookshop/generators/bookshop/app/app_generator.rb
View
@@ -22,8 +22,8 @@ Feature: We can create a new book project and build books
| builds/html |
| builds/pdf |
| builds/mobi |
-
- @no-clobber
+
+ @no-clobber
Scenario: Build a new pdf book
Given a file named "test_book/script/bookshop" should exist
When I cd to "test_book"
@@ -92,4 +92,13 @@ Feature: We can create a new book project and build books
| builds/mobi/book.mobi |
And the file "builds/mobi/OEBPS/book.html" should match /stylesheet.mobi.css/
And the file "builds/mobi/OEBPS/content.opf" should match /stylesheet.mobi.css/
-
+
+
+ @usage-error
+ Scenario: Run bookshop without arguments
+ When I run `bookshop`
+ Then the output should contain "Usage:\n bookshop new BOOK_NAME [options]"
+ @usage-error
+ Scenario: Run bookshop new without path
+ When I run `bookshop new`
+ Then the output should contain "Usage:\n bookshop new BOOK_NAME [options]"
View
@@ -1,4 +1,5 @@
require 'rbconfig'
+require 'bookshop/error'
require 'bookshop/script_bookshop_loader'
# If we are inside a Bookshop project this method performs an exec and thus
@@ -10,5 +11,8 @@
require 'bookshop/ruby_version_check'
Signal.trap("INT") { puts; exit }
-
-require 'bookshop/commands/application'
+begin
+require 'bookshop/commands/application'
+rescue Bookshop::Error => e
+ puts e.message
+end
View
@@ -0,0 +1,22 @@
+
+module Bookshop
+
+ class Error< StandardError
+
+ end
+
+ class ArgumentsError< Error
+
+ def to_s
+ " bookshop new BOOK_NAME [options]"
+ end
+
+ end
+
+ class GeneratorArgumentsError < ArgumentsError
+ def to_s
+ "Usage:\n" + super
+ end
+ end
+
+end
@@ -9,38 +9,42 @@ class AppGenerator < Thor::Group
include Thor::Actions
# Define arguments and options
- argument :app_path, :type => :string
+ argument :app_path, :optional=> true, :type => :string
# Define source root of application
def self.source_root
File.dirname(__FILE__)
end
- # Create the project from templates
- def create_base_project
- puts "creating base project"
- directory "templates", "#{app_path}"
- end
-
- # Adds third-party tools
- # def add_tools
- # directory "tools/", "#{app_path}/tools/"
- # end
-
- #Change the permissions so tools are executable
- def chmod_tools
- chmod "#{app_path}/script/epubcheck/epubcheck.jar", 0755
- chmod "#{app_path}/script/epubcheck/lib/jing.jar", 0755
- chmod "#{app_path}/script/epubcheck/lib/saxon.jar", 0755
- chmod "#{app_path}/script/kindlegen/kindlegen.exe", 0755
- chmod "#{app_path}/script/kindlegen/kindlegen_mac", 0755
- chmod "#{app_path}/script/kindlegen/kindlegen_linux", 0755
- end
-
+
+ # Create the project from templates
+ def create_base_project
+ raise GeneratorArgumentsError if app_path.nil?
+ puts "creating base project"
+ directory "templates", "#{app_path}"
+ end
+
+ # Adds third-party tools
+ # def add_tools
+ # directory "tools/", "#{app_path}/tools/"
+ # end
+
+ #Change the permissions so tools are executable
+ def chmod_tools
+ chmod "#{app_path}/script/epubcheck/epubcheck.jar", 0755
+ chmod "#{app_path}/script/epubcheck/lib/jing.jar", 0755
+ chmod "#{app_path}/script/epubcheck/lib/saxon.jar", 0755
+ chmod "#{app_path}/script/kindlegen/kindlegen.exe", 0755
+ chmod "#{app_path}/script/kindlegen/kindlegen_mac", 0755
+ chmod "#{app_path}/script/kindlegen/kindlegen_linux", 0755
+ end
+
+
+
protected
def self.banner
- "bookshop new #{self.arguments.map(&:usage).join(' ')} [options]"
+ raise ArgumentsError
end
end

0 comments on commit 0f3262b

Please sign in to comment.