mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-27 07:33:05 +00:00
add select group
This commit is contained in:
parent
fb0126d519
commit
15fa2b8847
3 changed files with 23 additions and 7 deletions
13
lib/Cli.rb
13
lib/Cli.rb
|
@ -227,6 +227,7 @@ class Cli
|
|||
|
||||
# Interactive mode
|
||||
def interactive()
|
||||
group = nil
|
||||
last_access = Time.now.to_i
|
||||
|
||||
while true
|
||||
|
@ -248,7 +249,7 @@ class Cli
|
|||
case command[0]
|
||||
when 'display', 'show', 'd', 's'
|
||||
if !command[1].nil? && !command[1].empty?
|
||||
self.display(command[1], command[2])
|
||||
self.display(command[1], group, command[2])
|
||||
end
|
||||
when 'add', 'a'
|
||||
add()
|
||||
|
@ -260,6 +261,12 @@ class Cli
|
|||
if !command[1].nil? && !command[1].empty?
|
||||
self.remove(command[1])
|
||||
end
|
||||
when 'group', 'g'
|
||||
if !command[1].nil? && !command[1].empty?
|
||||
group = command[1]
|
||||
else
|
||||
group = nil
|
||||
end
|
||||
when 'help', 'h', '?'
|
||||
puts '# Help'
|
||||
puts '# --------------------'
|
||||
|
@ -285,6 +292,10 @@ class Cli
|
|||
puts '# q'
|
||||
when 'quit', 'exit', 'q'
|
||||
break
|
||||
else
|
||||
if !command[0].nil? || !command[0].empty?
|
||||
puts 'Unknow command!'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -142,11 +142,11 @@ class MPW
|
|||
# @args: search -> the string to search
|
||||
# protocol -> the connection protocol (ssh, web, other)
|
||||
# @rtrn: a list with the resultat of the search
|
||||
def search(search, protocol=nil)
|
||||
def search(search, group=nil, protocol=nil)
|
||||
result = Array.new()
|
||||
@data.each do |row|
|
||||
if row[NAME] =~ /^.*#{search}.*$/ || row[SERVER] =~ /^.*#{search}.*$/ || row[COMMENT] =~ /^.*#{search}.*$/ || protocol.eql?('all')
|
||||
if protocol.nil? || protocol.eql?(row[PROTOCOL]) || protocol.eql?('all')
|
||||
if row[NAME] =~ /^.*#{search}.*$/ || row[SERVER] =~ /^.*#{search}.*$/ || row[COMMENT] =~ /^.*#{search}.*$/
|
||||
if (protocol.nil? || protocol.eql?(row[PROTOCOL])) && (group.nil? || group.eql?(row[GROUP]))
|
||||
result.push(row)
|
||||
end
|
||||
end
|
||||
|
@ -284,7 +284,7 @@ class MPW
|
|||
File.open(file, 'w+') do |file|
|
||||
@data.each do |row|
|
||||
row.delete_at(ID)
|
||||
file << "#{row.join(',')}\n"
|
||||
file << "#{row.join(';')}\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
7
mpw
7
mpw
|
@ -13,6 +13,7 @@ require "#{APP_ROOT}/lib/Cli.rb"
|
|||
options = {}
|
||||
options[:force] = false
|
||||
options[:format] = false
|
||||
options[:group] = nil
|
||||
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: mpw [options]"
|
||||
|
@ -34,6 +35,10 @@ OptionParser.new do |opts|
|
|||
options[:remove] = id
|
||||
end
|
||||
|
||||
opts.on("-g", "--group GROUP", "Select a group") do |group|
|
||||
options[:group] = group
|
||||
end
|
||||
|
||||
opts.on("-a", "--add", "Add an items") do |b|
|
||||
options[:add] = true
|
||||
end
|
||||
|
@ -76,7 +81,7 @@ if not options[:setup].nil?
|
|||
cli.setup()
|
||||
|
||||
elsif not options[:display].nil?
|
||||
cli.display(options[:display], options[:type], options[:format])
|
||||
cli.display(options[:display], options[:group], options[:type], options[:format])
|
||||
|
||||
# Remove an item
|
||||
elsif not options[:remove].nil?
|
||||
|
|
Loading…
Reference in a new issue