#!/usr/bin/env ruby require 'rubygems' require 'thor' begin if RUBY_VERSION <= '1.8.6' require 'ruby-debug' end rescue LoadError end $:.unshift(File.dirname(__FILE__) + '/../lib') require 'beet' require 'pp' WIN32 = (RUBY_PLATFORM =~ /win32|mingw|bccwin|cygwin/) rescue nil SUDO = (WIN32 || ENV['SUDOLESS']) ? '': 'sudo ' class BeetRunner < Thor map "-g" => :generate map "-j" => :just_recipe map "-h" => :help map "-v" => :version map "-l" => :list map "-d" => :display map "--list" => :list map "--display" => :display desc 'generate [app_name]', "the main app generate method" method_options %w(recipes -r) => :string, %w(project_type -p) => :project_type, %w(gems) => :string, %w(template -t) => :string, %w(save -s) => :string, %w(use -u) => :string def generate(app_name) executor = Beet::Executor.new(app_name, options) executor.start end desc 'just_recipe', "when you just need a recipe" method_options %w(recipes -r) => :string, %w(gems) => :string, %w(save -s) => :string, %w(use -u) => :string def just_recipe(app_name='.') executor = Beet::Executor.new(app_name, options.merge('generate' => false)) executor.start end desc 'list', "list what recipes and templates beet knows about" def list paths = [] paths << File.dirname(__FILE__) + '/../lib/beet/recipes/**/*.rb' paths << ENV['BEET_RECIPES_DIR'] + '/**/*.rb' if ENV['BEET_RECIPES_DIR'] recipes = paths.map do |path| Dir.glob(path) end.flatten.compact puts "\nRecipes: (e.g. beet -g app -r rails/git)" pp recipes puts "\nTemplates: (e.g. beet -g app -t bort)" pp TEMPLATE_LOCATIONS.sort.map {|array| array[0] + " => " + array[1]} puts "\nSaved Configurations:" print `cat #{ENV['HOME']}/.beet.yml` end desc 'display', "Display the code for the recipes/templates" method_options %w(recipes -r) => :string, %w(template -t) => :string def display(app_name='.') executor = Beet::Executor.new(app_name,options.merge('generate' => false, 'display' => true)) executor.start end desc 'version', "the current version of beet" def version version_file = File.dirname(__FILE__) + '/../VERSION' if File.exists?(version_file) and version = File.read(version_file) puts "Beet version: #{version}" end end desc 'help', 'help output' def help puts %{ Usage: #{$0} /path/to/your/app [options] Options: -g, --generate Run the generate command to build a project -j, --just_recipe Run the just_recipe command to only run specified recipes, templates, etc. -d, --display Instead of running, show the template or recipe body -r, --recipes Recipes to use -s, --save Save current set of options -u, --use Use a saved set of options --gems Gems to include Beet Info: -v, --version Show the Beet version number and quit. -l, --list Show the various recipes known to Beet and quit. -h, --help Show this help message and quit. General Options: Description: Beet is used to quickly generate applications. Example: beet generate example_app --recipes="rails/authlogic, rails/clean_files, rails/git" Same thing but shorter: beet -g example_app -r=rails/authlogic,rails/clean_files,rails/git } end end BeetRunner.start