mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-21 10:20:05 +00:00
add an alternatif format for the display
This commit is contained in:
parent
bf4b28e239
commit
314d6e87b4
2 changed files with 38 additions and 24 deletions
32
Cli.rb
32
Cli.rb
|
@ -54,19 +54,23 @@ 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)
|
def display(search, protocol=nil, format=nil)
|
||||||
result = @m.search(search, protocol)
|
result = @m.search(search, protocol)
|
||||||
|
|
||||||
if not result.empty?
|
if not result.empty?
|
||||||
result.each do |r|
|
result.each do |r|
|
||||||
displayFormat(r)
|
if format.nil? || !format
|
||||||
|
displayFormat(r)
|
||||||
|
else
|
||||||
|
displayFormatAlt(r)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "Nothing result!"
|
puts "Nothing result!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display an item
|
# Display an item in the default format
|
||||||
# @args: item -> an array with the item information
|
# @args: item -> an array with the item information
|
||||||
def displayFormat(item)
|
def displayFormat(item)
|
||||||
puts "# --------------------"
|
puts "# --------------------"
|
||||||
|
@ -74,13 +78,29 @@ class Cli
|
||||||
puts "# Name: #{item[MPW::NAME]}"
|
puts "# Name: #{item[MPW::NAME]}"
|
||||||
puts "# Group: #{item[MPW::GROUP]}"
|
puts "# Group: #{item[MPW::GROUP]}"
|
||||||
puts "# Server: #{item[MPW::SERVER]}"
|
puts "# Server: #{item[MPW::SERVER]}"
|
||||||
puts "# Type: #{item[MPW::PROTOCOL]}"
|
puts "# Protocol: #{item[MPW::PROTOCOL]}"
|
||||||
puts "# Login: #{item[MPW::LOGIN]}"
|
puts "# Login: #{item[MPW::LOGIN]}"
|
||||||
puts "# Password: #{item[MPW::PASSWORD]}"
|
puts "# Password: #{item[MPW::PASSWORD]}"
|
||||||
puts "# Port: #{item[MPW::PORT]}"
|
puts "# Port: #{item[MPW::PORT]}"
|
||||||
puts "# Comment: #{item[MPW::COMMENT]}"
|
puts "# Comment: #{item[MPW::COMMENT]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Display an item in the alternative format
|
||||||
|
# @args: item -> an array with the item information
|
||||||
|
def displayFormatAlt(item)
|
||||||
|
item[MPW::PORT].nil? ? (port = '') : (port = ":#{item[MPW::PORT]}")
|
||||||
|
|
||||||
|
if item[MPW::PASSWORD].nil? || item[MPW::PASSWORD].empty?
|
||||||
|
if item[MPW::LOGIN].index('@').eql?(nil)
|
||||||
|
puts "# #{item[MPW::ID]} #{item[MPW::PROTOCOL]}://#{item[MPW::LOGIN]}@#{item[MPW::SERVER]}#{port}"
|
||||||
|
else
|
||||||
|
puts "# #{item[MPW::ID]} #{item[MPW::PROTOCOL]}://{#{item[MPW::LOGIN]}}@#{item[MPW::SERVER]}#{port}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "# #{item[MPW::ID]} #{item[MPW::PROTOCOL]}://{#{item[MPW::LOGIN]}:#{item[MPW::PASSWORD]}}@#{item[MPW::SERVER]}#{port}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Form to add a new item
|
# Form to add a new item
|
||||||
def add()
|
def add()
|
||||||
row = Array.new()
|
row = Array.new()
|
||||||
|
@ -89,7 +109,7 @@ class Cli
|
||||||
name = ask("Enter the name: ")
|
name = ask("Enter the name: ")
|
||||||
group = ask("Enter the group [default=No Group]: ")
|
group = ask("Enter the group [default=No Group]: ")
|
||||||
server = ask("Enter the hostname or ip: ")
|
server = ask("Enter the hostname or ip: ")
|
||||||
protocol = ask("Enter the type of connection (ssh, web, other): ")
|
protocol = ask("Enter the protocol of the connection (ssh, http, other): ")
|
||||||
login = ask("Enter the login connection: ")
|
login = ask("Enter the login connection: ")
|
||||||
passwd = ask("Enter the the password: ")
|
passwd = ask("Enter the the password: ")
|
||||||
port = ask("Enter the connection port (optinal): ")
|
port = ask("Enter the connection port (optinal): ")
|
||||||
|
@ -117,7 +137,7 @@ class Cli
|
||||||
name = ask("Enter the name [#{row[MPW::NAME]}]: ")
|
name = ask("Enter the name [#{row[MPW::NAME]}]: ")
|
||||||
group = ask("Enter the group [#{row[MPW::GROUP]}]: ")
|
group = ask("Enter the group [#{row[MPW::GROUP]}]: ")
|
||||||
server = ask("Enter the hostname or ip [#{row[MPW::SERVER]}]: ")
|
server = ask("Enter the hostname or ip [#{row[MPW::SERVER]}]: ")
|
||||||
protocol = ask("Enter the type of connection [#{row[MPW::PROTOCOL]}]: ")
|
protocol = ask("Enter the protocol of the connection [#{row[MPW::PROTOCOL]}]: ")
|
||||||
login = ask("Enter the login connection [#{row[MPW::LOGIN]}]: ")
|
login = ask("Enter the login connection [#{row[MPW::LOGIN]}]: ")
|
||||||
passwd = ask("Enter the the password: ")
|
passwd = ask("Enter the the password: ")
|
||||||
port = ask("Enter the connection port [#{row[MPW::PORT]}]: ")
|
port = ask("Enter the connection port [#{row[MPW::PORT]}]: ")
|
||||||
|
|
30
mpw
30
mpw
|
@ -11,6 +11,9 @@ APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
||||||
require "#{APP_ROOT}/Cli.rb"
|
require "#{APP_ROOT}/Cli.rb"
|
||||||
|
|
||||||
options = {}
|
options = {}
|
||||||
|
options[:force] = false
|
||||||
|
options[:format] = false
|
||||||
|
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: mpw [options]"
|
opts.banner = "Usage: mpw [options]"
|
||||||
|
|
||||||
|
@ -19,7 +22,7 @@ OptionParser.new do |opts|
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.on("-A", "--show-all", "Show all items") do |b|
|
opts.on("-A", "--show-all", "Show all items") do |b|
|
||||||
options[:showall] = true
|
options[:type] = 'all'
|
||||||
options[:display] = ""
|
options[:display] = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,12 +58,17 @@ OptionParser.new do |opts|
|
||||||
options[:force] = true
|
options[:force] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on("-F", "--format", "Change the display format by an alternatif") do |b|
|
||||||
|
options[:format] = true
|
||||||
|
end
|
||||||
|
|
||||||
opts.on("-h", "--help", "Show this message") do |b|
|
opts.on("-h", "--help", "Show this message") do |b|
|
||||||
puts opts
|
puts opts
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
end.parse!
|
end.parse!
|
||||||
|
|
||||||
|
|
||||||
cli = Cli.new()
|
cli = Cli.new()
|
||||||
|
|
||||||
# Display the item's informations
|
# Display the item's informations
|
||||||
|
@ -68,21 +76,11 @@ if not options[:setup].nil?
|
||||||
cli.setup()
|
cli.setup()
|
||||||
|
|
||||||
elsif not options[:display].nil?
|
elsif not options[:display].nil?
|
||||||
if not options[:type].nil?
|
cli.display(options[:display], options[:type], options[:format])
|
||||||
cli.display(options[:display], options[:type])
|
|
||||||
elsif not options[:showall].nil?
|
|
||||||
cli.display(options[:display], 'all')
|
|
||||||
else
|
|
||||||
cli.display(options[:display])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Remove an item
|
# Remove an item
|
||||||
elsif not options[:remove].nil?
|
elsif not options[:remove].nil?
|
||||||
if not options[:force].nil?
|
cli.remove(options[:remove], options[:force])
|
||||||
cli.remove(options[:remove], options[:force])
|
|
||||||
else
|
|
||||||
cli.remove(options[:remove])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Update an item
|
# Update an item
|
||||||
elsif not options[:update].nil?
|
elsif not options[:update].nil?
|
||||||
|
@ -98,11 +96,7 @@ elsif not options[:export].nil?
|
||||||
|
|
||||||
# Add a new item
|
# Add a new item
|
||||||
elsif not options[:import].nil?
|
elsif not options[:import].nil?
|
||||||
if not options[:force].nil?
|
cli.import(options[:import], options[:force])
|
||||||
cli.import(options[:import], options[:force])
|
|
||||||
else
|
|
||||||
cli.import(options[:import])
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
puts "For help add option -h or --help"
|
puts "For help add option -h or --help"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue