diff --git a/lib/MPW.rb b/lib/MPW.rb index 8d770d3..c948606 100644 --- a/lib/MPW.rb +++ b/lib/MPW.rb @@ -126,20 +126,23 @@ module MPW def list(options={}) result = [] - if not defined?(options[:search]) or options[:search].nil? - search = '' - else - search = options[:search].downcase - end - + search = options[:search].to_s.downcase + group = options[:group].to_s.downcase + protocol = options[:protocol].to_s.downcase + @data.each do |item| - name = item.name.nil? ? nil : item.name.downcase - host = item.host.nil? ? nil : item.host.downcase - comment = item.comment.nil? ? nil : item.comment.downcase - - if name =~ /^.*#{search}.*$/ or host =~ /^.*#{search}.*$/ or comment =~ /^.*#{search}.*$/ - result.push(item) + next if not group.empty? and not group.eql?(item.group.downcase) + next if not protocol.empty? and not protocol.eql?(item.protocol.downcase) + + name = item.name.to_s.downcase + host = item.host.to_s.downcase + comment = item.comment.to_s.downcase + + if not name =~ /^.*#{search}.*$/ and not host =~ /^.*#{search}.*$/ and not comment =~ /^.*#{search}.*$/ + next end + + result.push(item) end return result diff --git a/lib/UI/Cli.rb b/lib/UI/Cli.rb index eba7273..9352ed9 100644 --- a/lib/UI/Cli.rb +++ b/lib/UI/Cli.rb @@ -134,8 +134,8 @@ class Cli # Display the query's result # @args: search -> the string to search # protocol -> search from a particular protocol - def display(search, protocol=nil, group=nil) - result = @mpw.list(search: search) + def display(options={}) + result = @mpw.list(options) case result.length when 0 diff --git a/mpw b/mpw index bc63313..ad632b1 100755 --- a/mpw +++ b/mpw @@ -77,8 +77,8 @@ OptionParser.new do |opts| options[:setup] = true end - opts.on('-p', '--protocol PROTOCOL', I18n.t('option.protocol')) do |type| - options[:type] = type + opts.on('-p', '--protocol PROTOCOL', I18n.t('option.protocol')) do |protocol| + options[:protocol] = protocol end opts.on('-e', '--export FILE', I18n.t('option.export')) do |file| @@ -130,7 +130,12 @@ cli.sync # Display the item's informations if not options[:show].nil? - cli.display(options[:show], options[:group], options[:type]) + opts = {search: options[:show], + group: options[:group], + protocol: options[:protocol], + } + + cli.display(opts) # Remove an item elsif not options[:delete].nil?