#!/usr/bin/env ruby # # Created by Luke Bayes on 2007-4-29. # Copyright (c) 2007. All rights reserved. begin require 'rubygems' rescue LoadError # no rubygems to load, so we fail silently end $:.push(File.dirname(__FILE__) + '/../lib') require 'sprout' require 'sprout/generator' require 'optparse' OPTIONS = { :sources => [], :project_name => nil, :sprout_name => nil, :requirements => nil, :remove_all => false } def fail_with(opts, message) puts "[ERROR] #{message}" puts "" puts opts exit end parser = OptionParser.new do |opts| opts.banner = < 0) set_sources OPTIONS[:sources] end if(ARGV.size > 0) if(OPTIONS[:sprout_name]) OPTIONS[:project_name] = ARGV.pop if(OPTIONS[:project_name] == "=") fail_with(opts, "Invalid project name #{OPTIONS[:project_name]}") elsif(OPTIONS[:project_name] =~ /Test$/) fail_with(opts, "Your project name should not match /Test$/ as this will quickly cause problems when generating test cases and test suites") end else fail_with(opts, "You must provide a sprout name argument such as, '-n as2' or '-n as3'") end elsif(OPTIONS[:remove_all]) exit else fail_with(opts, "Expected a sprout bundle name and project name like: 'sprout -n as2 SomeProject'") end end ############################################# sprout_name = OPTIONS[:sprout_name] sprout_requirements = OPTIONS[:requirements] project_name = OPTIONS[:project_name] ############################################# puts ">> Creating new project '#{project_name}' with #{sprout_name}" Sprout::Sprout.project_name = project_name begin # Fallback if a version was specified if(sprout_requirements) sprout(sprout_name, sprout_requirements) end # Try to run the generator against user home and existing gems first Sprout::Sprout.generate(sprout_name, 'project', [project_name]) rescue RubiGen::GeneratorError # Failing that, try to download a sprout gem by name sprout(sprout_name, sprout_requirements) # Then try again.... Sprout::Sprout.generate(sprout_name, 'project', [project_name]) end Sprout::Log.flush