diff --git a/lib/Cli.rb b/lib/Cli.rb index 649de7e..fd50a40 100644 --- a/lib/Cli.rb +++ b/lib/Cli.rb @@ -102,7 +102,7 @@ class Cli puts "# Add a new item" puts "# --------------------" 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: ") protocol = ask("Enter the protocol of the connection (ssh, http, other): ") login = ask("Enter the login connection: ") @@ -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 diff --git a/lib/MPW.rb b/lib/MPW.rb index 496189e..9ebea76 100644 --- a/lib/MPW.rb +++ b/lib/MPW.rb @@ -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 diff --git a/mpw b/mpw index 2f26b56..568c75e 100755 --- a/mpw +++ b/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?