1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-17 08:30:04 +00:00

improve search options

This commit is contained in:
nishiki 2015-02-14 10:42:03 +01:00
parent ed2d7e624d
commit 7f45037366
3 changed files with 25 additions and 17 deletions

View file

@ -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

View file

@ -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

11
mpw
View file

@ -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?