qwandry/bin/qw

59 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/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|
2010-11-09 03:39:00 +00:00
opts.banner = "Usage: qwandry [options] name"
opts.separator ""
opts.on("-r", "--repo LABEL", "Only search in repository LABEL","Repositories:", *@qwandry.repositories.keys.map{|k| "* #{k}"}) do |label|
if @qwandry.repositories.has_key? label
@repository_label = label
else
STDERR.puts "Repository '#{label}' in not available, searching all repositories"
end
2010-11-09 03:39:00 +00:00
end
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
2010-11-09 03:39:00 +00:00
packages = @qwandry.find(name,@repository_label)
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