diff --git a/bin/qw b/bin/qw index 8bf1463..55e9378 100755 --- a/bin/qw +++ b/bin/qw @@ -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 diff --git a/lib/qwandry.rb b/lib/qwandry.rb index 5a6dd47..19e795b 100644 --- a/lib/qwandry.rb +++ b/lib/qwandry.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby require 'optparse' +require 'set' # Informal Spec: # diff --git a/lib/qwandry/launcher.rb b/lib/qwandry/launcher.rb index 961498f..240417a 100644 --- a/lib/qwandry/launcher.rb +++ b/lib/qwandry/launcher.rb @@ -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!