allow searching a specific repository

This commit is contained in:
Adam Sanderson 2010-11-08 19:39:00 -08:00
parent 912fdb4882
commit 127a76f5ba
2 changed files with 9 additions and 5 deletions

7
bin/qw
View File

@ -8,9 +8,12 @@ require "qwandry"
load('~/.qwandry/repositories.rb') if File.exists?('~/.qwandry/repositories.rb') load('~/.qwandry/repositories.rb') if File.exists?('~/.qwandry/repositories.rb')
opts = OptionParser.new do |opts| opts = OptionParser.new do |opts|
opts.banner = "Usage: qwandry [options] name [version]" opts.banner = "Usage: qwandry [options] name"
opts.separator "" opts.separator ""
opts.on("-r", "--repo LABEL", "Only search in repository LABEL") do |label|
@repository_label = label
end
opts.separator "Known Repositories: #{@qwandry.repositories.keys.join(", ")}" opts.separator "Known Repositories: #{@qwandry.repositories.keys.join(", ")}"
opts.on("-e", "--editor EDITOR", "Use EDITOR to open the package") do |editor| opts.on("-e", "--editor EDITOR", "Use EDITOR to open the package") do |editor|
@qwandry.editor = editor @qwandry.editor = editor
@ -30,7 +33,7 @@ if ARGV.length != 1
end end
name = ARGV.pop name = ARGV.pop
packages = @qwandry.find(name) packages = @qwandry.find(name,@repository_label)
package = nil package = nil
case packages.length case packages.length

View File

@ -1,5 +1,5 @@
# Launcher is the core Qwandry class, it coordinates finding and launching # Launcher is the core Qwandry class, it coordinates finding and launching
# a package. It is driven externaly by a UI. # a package. It is driven externaly by a UI, for instance the `bin/qw`.
module Qwandry module Qwandry
class Launcher class Launcher
# The default editor to be used by Qwandry#launch. # The default editor to be used by Qwandry#launch.
@ -23,9 +23,10 @@ module Qwandry
end end
# Searches all of the loaded repositories for `name` # Searches all of the loaded repositories for `name`
def find(name) def find(name,repository_label=nil)
packages = [] packages = []
@repositories.each do |label, repos| @repositories.each do |label, repos|
next if repository_label && repository_label != label
repos.each do |repo| repos.each do |repo|
packages.concat(repo.scan(name)) packages.concat(repo.scan(name))
end end
@ -33,7 +34,7 @@ module Qwandry
packages packages
end end
# Launches a `package`, unless set, `editor` will check against the environment. # Launches a `package`. Unless `editor` will check against the environment by default.
def launch(package, editor=nil) def launch(package, editor=nil)
editor ||= @editor || ENV['VISUAL'] || ENV['EDITOR'] editor ||= @editor || ENV['VISUAL'] || ENV['EDITOR']
system editor, *package.paths system editor, *package.paths