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