#!/usr/bin/env ruby # Add qwandry's library to the load path $:.unshift File.dirname(__FILE__) + '/../lib' # Require it require "qwandry.rb" recipes = Qwandry::Recipe.load_recipes opts = OptionParser.new do |opts| opts.banner = "Usage: qwandry [options] name" opts.separator "" opts.on("-r", "--recipe RECIPE", "Use paths from RECIPE","Recipes:", *recipes.map{|r| "* #{r.name}: #{r.description}"}) do |recipe| @recipe_name = recipe end opts.separator "" opts.on("-e", "--editor EDITOR", "Use EDITOR to open the package") do |editor| @editor = editor end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end opts.parse! ARGV if ARGV.length != 1 puts opts exit(1) end # Create launcher @qwandry = Qwandry::Launcher.new # Configure default values @qwandry.editor = @editor if @editor # Load recipe @recipe_name ||= ENV['QW_DEFAULT'] || 'default' @recipe = recipes.find{|r| r.name.downcase == @recipe_name } unless @recipe STDERR.puts "Could not find recipe '#{@recipe_name}'" exit(1) end # Configure Qwandry @recipe.new.configure(@qwandry) # Warn if there are no repositories if @qwandry.repositories.empty? STDERR.puts "Warning: no repositories were defined in '#{@recipe_path}'" end name = ARGV.pop packages = @qwandry.find(name) package = nil case packages.length when 0 puts "No packages matched '#{name}'" exit 404 # Package not found -- hehe, super lame. when 1 package = packages.first else packages.each_with_index do |package, index| puts "%3d. %s" % [index+1, package.name] end print ">> " index = gets.to_i-1 package = packages[index] end @qwandry.launch(package) if package