Sensible mechanism for setting default repositories.

This commit is contained in:
Adam Sanderson 2010-11-10 18:56:30 -08:00
parent 39d2b456a7
commit 1668fc3a55
3 changed files with 22 additions and 12 deletions

10
bin/qw
View File

@ -11,12 +11,8 @@ opts = OptionParser.new do |opts|
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
opts.on("-r", "--repo LABELS", Array, "Search in LABELS, default: #{@qwandry.active.to_a.join(',')}","Available Repositories:", *@qwandry.repositories.keys.map{|k| " #{k}"}) do |labels|
@qwandry.active.replace(labels)
end
opts.separator ""
@ -40,7 +36,7 @@ end
@qwandry.editor = @editor if @editor
name = ARGV.pop
packages = @qwandry.find(name, @repository_label)
packages = @qwandry.find(name)
package = nil
case packages.length

View File

@ -1,5 +1,6 @@
#!/usr/bin/env ruby
require 'optparse'
require 'set'
# Informal Spec:
#

View File

@ -4,16 +4,20 @@ module Qwandry
class Launcher
# The default editor to be used by Qwandry#launch.
attr_accessor :editor
# The set of active repositories
attr_reader :active
# Returns the repositories the Launcher will use.
attr_reader :repositories
def initialize
@repositories = Hash.new{|h,k| h[k] = []}
@active = Set.new
configure_repositories!
custom_configuration!
end
# Adds a repository path to Qwandry's Launcher.
# `label` is used to label packages residing in the folder `path`.
# The `repository_type` controls the class used to index the `path`.
@ -25,12 +29,19 @@ module Qwandry
@repositories[label] << repository_type.new(label, path)
end
end
def activate(*labels)
labels.each{|label| @active.add label.to_s}
end
def deactivate(*labels)
labels.each{|label| @active.delete label.to_s}
end
# Searches all of the loaded repositories for `name`
def find(name, required_label=nil)
def find(name)
packages = []
@repositories.each do |label, repos|
next if required_label && required_label != label
@repositories.select{|label,_| @active.include? label }.each do |label, repos|
repos.each do |repo|
packages.concat(repo.scan(name))
end
@ -61,6 +72,8 @@ module Qwandry
($:).grep(/gems/).map{|p| p[/.+\/gems\//]}.uniq.each do |path|
add :gem, path
end
activate :ruby, :gem
end
def custom_configuration!