mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +00:00
improve search options
This commit is contained in:
parent
ed2d7e624d
commit
7f45037366
3 changed files with 25 additions and 17 deletions
27
lib/MPW.rb
27
lib/MPW.rb
|
@ -126,20 +126,23 @@ module MPW
|
||||||
def list(options={})
|
def list(options={})
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
if not defined?(options[:search]) or options[:search].nil?
|
search = options[:search].to_s.downcase
|
||||||
search = ''
|
group = options[:group].to_s.downcase
|
||||||
else
|
protocol = options[:protocol].to_s.downcase
|
||||||
search = options[:search].downcase
|
|
||||||
end
|
|
||||||
|
|
||||||
@data.each do |item|
|
@data.each do |item|
|
||||||
name = item.name.nil? ? nil : item.name.downcase
|
next if not group.empty? and not group.eql?(item.group.downcase)
|
||||||
host = item.host.nil? ? nil : item.host.downcase
|
next if not protocol.empty? and not protocol.eql?(item.protocol.downcase)
|
||||||
comment = item.comment.nil? ? nil : item.comment.downcase
|
|
||||||
|
name = item.name.to_s.downcase
|
||||||
if name =~ /^.*#{search}.*$/ or host =~ /^.*#{search}.*$/ or comment =~ /^.*#{search}.*$/
|
host = item.host.to_s.downcase
|
||||||
result.push(item)
|
comment = item.comment.to_s.downcase
|
||||||
|
|
||||||
|
if not name =~ /^.*#{search}.*$/ and not host =~ /^.*#{search}.*$/ and not comment =~ /^.*#{search}.*$/
|
||||||
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
result.push(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -134,8 +134,8 @@ class Cli
|
||||||
# Display the query's result
|
# Display the query's result
|
||||||
# @args: search -> the string to search
|
# @args: search -> the string to search
|
||||||
# protocol -> search from a particular protocol
|
# protocol -> search from a particular protocol
|
||||||
def display(search, protocol=nil, group=nil)
|
def display(options={})
|
||||||
result = @mpw.list(search: search)
|
result = @mpw.list(options)
|
||||||
|
|
||||||
case result.length
|
case result.length
|
||||||
when 0
|
when 0
|
||||||
|
|
11
mpw
11
mpw
|
@ -77,8 +77,8 @@ OptionParser.new do |opts|
|
||||||
options[:setup] = true
|
options[:setup] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-p', '--protocol PROTOCOL', I18n.t('option.protocol')) do |type|
|
opts.on('-p', '--protocol PROTOCOL', I18n.t('option.protocol')) do |protocol|
|
||||||
options[:type] = type
|
options[:protocol] = protocol
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on('-e', '--export FILE', I18n.t('option.export')) do |file|
|
opts.on('-e', '--export FILE', I18n.t('option.export')) do |file|
|
||||||
|
@ -130,7 +130,12 @@ cli.sync
|
||||||
|
|
||||||
# Display the item's informations
|
# Display the item's informations
|
||||||
if not options[:show].nil?
|
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
|
# Remove an item
|
||||||
elsif not options[:delete].nil?
|
elsif not options[:delete].nil?
|
||||||
|
|
Loading…
Add table
Reference in a new issue