Class: Bicho::CLI::Commands::Search

Inherits:
Bicho::CLI::Command show all
Defined in:
lib/bicho/cli/commands/search.rb

Instance Attribute Summary

Attributes inherited from Bicho::CLI::Command

#t

Instance Method Summary (collapse)

Methods inherited from Bicho::CLI::Command

#initialize, opt, options, #parse_options, #parser

Methods included from Logging

#logger, logger, logger=

Constructor Details

This class inherits a constructor from Bicho::CLI::Command

Instance Method Details

- (Object) do(global_opts, opts, args)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bicho/cli/commands/search.rb', line 41

def do(global_opts, opts, args)
  server = ::Bicho::Client.new(global_opts[:bugzilla])
  # for most parameter we accept arrays, and also multi mode
  # this means parameters come in arrays of arrays
  query = ::Bicho::Query.new
  opts.each do |n,v|
    # skip any option that is not part of SEARCH_FIELDS
    next if not Bicho::SEARCH_FIELDS.map { |x| x[0] }.include?(n)
    next if v.nil? || v.flatten.empty?
    v.flatten.each do |single_val|
      query.send(n.to_sym, single_val)
    end
  end

  server.search_bugs(query).each do |bug|
    t.say("#{t.color(bug.id, :headline)} #{bug.summary}")
  end
  return 0
end