From e5b64406ce8b4d2c59abbbd50f3ef1d519d58f51 Mon Sep 17 00:00:00 2001 From: Adam Sanderson Date: Tue, 17 Aug 2010 21:42:57 -0700 Subject: [PATCH] Create a proper executable for qwandry, qw --- bin/qw | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/qwandry.rb | 49 ----------------------------------------------- 2 files changed, 52 insertions(+), 49 deletions(-) mode change 100755 => 100644 lib/qwandry.rb diff --git a/bin/qw b/bin/qw index e69de29..51f994f 100755 --- a/bin/qw +++ b/bin/qw @@ -0,0 +1,52 @@ +#!/usr/bin/env ruby +# Add qwandry's library to the load path +$: << File.dirname(__FILE__) + '/../lib' +# Require it +require "qwandry" + +@qwandry = Qwandry::Launcher.new +load('~/.qwandry/repositories.rb') if File.exists?('~/.qwandry/repositories.rb') + +opts = OptionParser.new do |opts| + opts.banner = "Usage: qwandry [options] name [version]" + opts.separator "" + + opts.separator "Known Repositories: #{@qwandry.repositories.keys.join(", ")}" + opts.on("-e", "--editor EDITOR", "Use EDITOR to open the package") do |editor| + @qwandry.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 + +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 \ No newline at end of file diff --git a/lib/qwandry.rb b/lib/qwandry.rb old mode 100755 new mode 100644 index aa3da1a..6fa765f --- a/lib/qwandry.rb +++ b/lib/qwandry.rb @@ -18,53 +18,4 @@ module Qwandry autoload :Repository, "qwandry/repository" autoload :FlatRepository, "qwandry/flat_repository" autoload :Package, "qwandry/package" -end - -if __FILE__ == $0 - @qwandry = Qwandry::Launcher.new - load('~/.qwandry/repositories.rb') if File.exists?('~/.qwandry/repositories.rb') - - opts = OptionParser.new do |opts| - opts.banner = "Usage: qwandry [options] name [version]" - opts.separator "" - - opts.separator "Known Repositories: #{@qwandry.repositories.keys.join(", ")}" - opts.on("-e", "--editor EDITOR", "Use EDITOR to open the package") do |editor| - @qwandry.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 - - 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 end \ No newline at end of file