lib/apimaster/generators/scripts.rb in apimaster-0.0.2 vs lib/apimaster/generators/scripts.rb in apimaster-0.0.3
- old
+ new
@@ -5,11 +5,13 @@
require File.dirname(__FILE__) + '/manifest'
require File.dirname(__FILE__) + '/simple_logger'
require File.dirname(__FILE__) + '/base'
require File.dirname(__FILE__) + '/command'
-require File.dirname(__FILE__) + '/application'
+require File.dirname(__FILE__) + '/app_generator'
+require File.dirname(__FILE__) + '/model_generator'
+require File.dirname(__FILE__) + '/controller_generator'
module Apimaster::Generators
module Scripts
# Generator scripts handle command-line invocation. Each script
@@ -23,11 +25,13 @@
attr_reader :stdout
attr_accessor :commands
def initialize
@commands ||= {}
- register("new", Application)
+ register("new", AppGenerator)
+ register("model", ModelGenerator)
+ register("controller", ControllerGenerator)
end
def register name, klass
@commands[name] = klass
end
@@ -42,23 +46,22 @@
rescue OptionParser::InvalidOption => e
# Don't cry, script. Generators want what you think is invalid.
end
# Look up generator instance and invoke command on it.
- if command = args.shift
- raise "Invalid command name: #{command}" unless commands.key?(command)
- commands[command].new(args).run
- else
- usage
+ begin
+ command = args.shift
+ if command and commands.key?(command)
+ commands[command].new(args).run
+ else
+ raise "Invalid command name: #{command}"
+ end
+ rescue => e
+ stdout.puts e
+ stdout.puts " #{e.backtrace.join("\n ")}\n" if options[:backtrace]
+ raise SystemExit unless options[:no_exit]
end
- end
- rescue => e
- stdout.puts e
- stdout.puts " #{e.backtrace.join("\n ")}\n" if options[:backtrace]
- raise SystemExit unless options[:no_exit]
end
- def usage
- stdout.puts "apimaster new your_app_name"
- end
+ end
end
end