require 'optparse' module Architect class << self def application @application ||= Architect::Application.new end end class Application attr_reader :args, :command, :options def initialize(path = nil) if path @root = File.expand_path(path) else @root = File.expand_path(Dir.getwd) end end def run parse_command if @command == :generate parse_arguments parse_generate_options else parse_options parse_arguments end if @command self.send @command unless @command =~ /^-/ else help end end def create app_name = @args.first if @args[1] sub_dir = @args[1] unless @args[1].match /^-/ end blueprint = @options[:blueprint] raise 'you must specify a project name: architect create [project_name]' if args[0].nil? @root = File.expand_path sub_dir if sub_dir config = { name: app_name, blueprint: blueprint } require "#{blueprint}-architecture" unless blueprint == 'default' project = ArchitectureJS::BLUEPRINTS[blueprint].new(config, @root) project.create end def generate project_path = File.expand_path(Dir.getwd) project = ArchitectureJS::Blueprint.new_from_config(project_path) config = { arguments: @args, template: @args.first, filename: @args[1], options: @template_options } begin project.generator.generate config rescue Exception => e puts e.message puts "Be sure you ran the command correctly (architect generate