#!/usr/bin/env ruby require 'rubygems' require 'thor' begin require 'ruby-debug' 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" method_options %w(templates -t) => :string def list(pattern=nil) 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 recipes = recipes.grep(Regexp.new(pattern)) if pattern puts "\nRecipes: (e.g. beet -g app -r rails/git)" pp recipes if options[:templates] puts "\nTemplates: (e.g. beet -g app -t bort)" pp TEMPLATE_LOCATIONS.sort.map {|array| array[0] + " => " + array[1]} end 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: beet /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 [text] Show the various recipes known to Beet and quit. Pass in [text] to limit output to recipes that include [text] -h, --help Show this help message and quit. General Options: Description: Beet is used to quickly generate applications. Example: beet generate example_app --recipes="rails3/auth/devise, rails3/clean_files, rails3/git" Same thing but shorter: beet -g example_app -r=rails3/auth/devise,rails3/clean_files,rails3/git } end end BeetRunner.start