Module: Groundwork
- Defined in:
- lib/recipe.rb,
lib/options.rb,
lib/groundwork.rb,
lib/recipe_class.rb,
lib/recipe_unpacker.rb
Defined Under Namespace
Classes: Recipe, RecipeUnpacker, TarWrapper
Constant Summary collapse
- GROUNDWORK_VERSION =
File.read(File.join(File.dirname(__FILE__), "..", "VERSION"))
- COMMANDS =
Dir[File.join(File.dirname(__FILE__),"..","commands","*.rb")].map{|file| File.basename(file,".rb") }
Class Method Summary collapse
-
.known_recipes ⇒ Object
Return a hash of all known recipes, the included ones and the ones in .groundwork.
- .parse_options(opts = ARGV) ⇒ Object
- .short_for(cmd_start, all_commands = (COMMANDS | known_recipes.keys)) ⇒ Object
Class Method Details
.known_recipes ⇒ Object
Return a hash of all known recipes, the included ones and the ones in .groundwork
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/groundwork.rb', line 14 def self.known_recipes recipes = {} Dir[File.join(File.dirname(__FILE__),"..","recipes","*.recipe")].each do |recipe| recipes[File.basename(recipe,".recipe")] = recipe end dot_groundwork = File.("~/.groundwork") if File.directory?(dot_groundwork) Dir[File.join(dot_groundwork,"*.recipe")].each do |recipe| recipes[File.basename(recipe,".recipe")] = recipe end end recipes end |
.parse_options(opts = ARGV) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/options.rb', line 7 def self. opts=ARGV global_opts = Trollop::(opts) do <<-STR Usage: groundwork [global_options] <command> [command_options] Commands: generate - Generate a recipe for the current directory compile - Compile a .recipe.rb file into a .recipe install - Install a compiled .recipe file into ~/.groundwork list - List all recipes Use "groundwork <command> -h" for command-specific help Global options are: STR version GROUNDWORK_VERSION stop_on_unknown end cmd=short_for(opts.shift) return({ :options=>global_opts, :command=>cmd, :remainder=>opts }) end |
.short_for(cmd_start, all_commands = (COMMANDS | known_recipes.keys)) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/options.rb', line 35 def self.short_for cmd_start, all_commands=(COMMANDS | known_recipes.keys) return cmd_start unless cmd_start return cmd_start if all_commands.index(cmd_start) completions = all_commands.abbrev(cmd_start) if completions[cmd_start] completions[cmd_start] elsif completions.values.uniq.empty? raise RuntimeError.new("Unknown command \"#{cmd_start}\".") else raise RuntimeError.new("\"#{cmd_start}\" is ambiguous. Which did you mean:\n\t"+cmd_poss.join("\n\t")) end end |