Sha256: 91b2b9385fbd99a9c2d15c0a28652bbb83694fe91361ad489b515fb27b133608
Contents?: true
Size: 1.84 KB
Versions: 1
Compression:
Stored size: 1.84 KB
Contents
module Apimaster end require File.dirname(__FILE__) + '/options' 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' module Apimaster::Generators module Scripts # Generator scripts handle command-line invocation. Each script # responds to an invoke! class method which handles option parsing # and generator invocation. class Base include Options default_options :collision => :ask, :quiet => false attr_reader :stdout attr_accessor :commands def initialize @commands ||= {} register("new", Application) end def register name, klass @commands[name] = klass end # Run the generator script. Takes an array of unparsed arguments # and a hash of parsed arguments, takes the generator as an option # or first remaining argument, and invokes the requested command. def run(args = [], runtime_options = {}) @stdout = runtime_options[:stdout] || $stdout begin parse!(args.dup, runtime_options) 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 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
apimaster-0.0.2 | lib/apimaster/generators/scripts.rb |