mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-18 17:10:04 +00:00
add select form when multiple result
This commit is contained in:
parent
40291632eb
commit
f5b98de4c1
5 changed files with 37 additions and 10 deletions
|
@ -31,6 +31,9 @@ en:
|
||||||
upload: "Can't upload the file on the server!"
|
upload: "Can't upload the file on the server!"
|
||||||
unknown: "An unknown error is occured!"
|
unknown: "An unknown error is occured!"
|
||||||
|
|
||||||
|
warning:
|
||||||
|
select: 'Your choice is not a valid element!'
|
||||||
|
|
||||||
option:
|
option:
|
||||||
usage: "Usage"
|
usage: "Usage"
|
||||||
show: "Search and show the items"
|
show: "Search and show the items"
|
||||||
|
@ -51,6 +54,7 @@ en:
|
||||||
help: "Show this help message"
|
help: "Show this help message"
|
||||||
|
|
||||||
form:
|
form:
|
||||||
|
select: "Select the item: "
|
||||||
add:
|
add:
|
||||||
title: "Add a new item"
|
title: "Add a new item"
|
||||||
name: "Enter the name: "
|
name: "Enter the name: "
|
||||||
|
@ -122,6 +126,7 @@ en:
|
||||||
port: "Port"
|
port: "Port"
|
||||||
protocol: "Protocol"
|
protocol: "Protocol"
|
||||||
server: "Server"
|
server: "Server"
|
||||||
|
warning: "Warning"
|
||||||
|
|
||||||
ssh:
|
ssh:
|
||||||
option:
|
option:
|
||||||
|
|
|
@ -31,6 +31,9 @@ fr:
|
||||||
upload: "Impossible d'envoyer le fichier sur le serveur!"
|
upload: "Impossible d'envoyer le fichier sur le serveur!"
|
||||||
unknown: "Une erreur inconnue est survenue!"
|
unknown: "Une erreur inconnue est survenue!"
|
||||||
|
|
||||||
|
warning:
|
||||||
|
select: "Votre choix n'est pas un élément valide!"
|
||||||
|
|
||||||
option:
|
option:
|
||||||
usage: "Utilisation"
|
usage: "Utilisation"
|
||||||
show: "Recherche et affiche les éléments"
|
show: "Recherche et affiche les éléments"
|
||||||
|
@ -51,6 +54,7 @@ fr:
|
||||||
help: "Affiche ce message d'aide"
|
help: "Affiche ce message d'aide"
|
||||||
|
|
||||||
form:
|
form:
|
||||||
|
select: "Sélectionner l'élément: "
|
||||||
add:
|
add:
|
||||||
title: "Ajout d'un nouvel élément"
|
title: "Ajout d'un nouvel élément"
|
||||||
name: "Entrez le nom: "
|
name: "Entrez le nom: "
|
||||||
|
@ -122,6 +126,7 @@ fr:
|
||||||
port: "Port"
|
port: "Port"
|
||||||
protocol: "Protocol"
|
protocol: "Protocol"
|
||||||
server: "Serveur"
|
server: "Serveur"
|
||||||
|
warning: "Warning"
|
||||||
|
|
||||||
ssh:
|
ssh:
|
||||||
option:
|
option:
|
||||||
|
|
|
@ -90,7 +90,7 @@ module MPW
|
||||||
file << msg['data']
|
file << msg['data']
|
||||||
end
|
end
|
||||||
|
|
||||||
mpw = MPW.new(tmp_file)
|
mpw = MPW.new(tmp_file, @gpg_key)
|
||||||
if not mpw.decrypt(gpg_password)
|
if not mpw.decrypt(gpg_password)
|
||||||
@error_msg = mpw.error_msg
|
@error_msg = mpw.error_msg
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Cli
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not @config.sync_host.nil? and not @config.sync_port.nil?
|
if not @config.sync_host.nil? and not @config.sync_port.nil?
|
||||||
if not @sync.connect(@config.sync_host, @config.sync_user, @config.sync_pwd, @config.sync_path, @config.sync_port)
|
if not @sync.connect(@config.sync_host, @config.sync_user, @config.sync_pwd, @config.sync_path, @config.sync_port)
|
||||||
puts "#{I18n.t('display.error')} #1: #{@sync.error_msg}".red
|
puts "#{I18n.t('display.error')} #1: #{@sync.error_msg}".red
|
||||||
|
@ -166,21 +166,37 @@ 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, format=nil)
|
def display(search, protocol=nil, group=nil)
|
||||||
result = @mpw.search(search, group, protocol)
|
result = @mpw.search(search, group, protocol)
|
||||||
|
|
||||||
if not result.empty?
|
case result.length
|
||||||
result.each do |r|
|
when 0
|
||||||
display_item(r)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
puts I18n.t('display.nothing')
|
puts I18n.t('display.nothing')
|
||||||
|
when 1
|
||||||
|
display_item(result.first)
|
||||||
|
else
|
||||||
|
i = 1
|
||||||
|
result.each do |r|
|
||||||
|
print "#{i}: ".cyan
|
||||||
|
print r['name']
|
||||||
|
print " -> #{r['comment']}".magenta if not r['comment'].to_s.empty?
|
||||||
|
print "\n"
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
end
|
||||||
|
choice = ask(I18n.t('form.select')).to_i
|
||||||
|
|
||||||
|
if choice >= 1 and choice < i
|
||||||
|
display_item(result[choice-1])
|
||||||
|
else
|
||||||
|
puts "#{I18n.t('display.warning')}: #{I18n.t('warning.select')}".yellow
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display an item in the default format
|
# Display an item in the default format
|
||||||
# @args: item -> an array with the item information
|
# @args: item -> an array with the item information
|
||||||
def diplay_item(item)
|
def display_item(item)
|
||||||
puts '--------------------'
|
puts '--------------------'
|
||||||
puts "Id: #{item['id']}"
|
puts "Id: #{item['id']}"
|
||||||
puts "#{I18n.t('display.name')}: #{item['name']}"
|
puts "#{I18n.t('display.name')}: #{item['name']}"
|
||||||
|
@ -193,6 +209,7 @@ class Cli
|
||||||
puts "#{I18n.t('display.comment')}: #{item['comment']}"
|
puts "#{I18n.t('display.comment')}: #{item['comment']}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Form to add a new item
|
# Form to add a new item
|
||||||
def add
|
def add
|
||||||
row = []
|
row = []
|
||||||
|
|
2
mpw
2
mpw
|
@ -133,7 +133,7 @@ cli.sync
|
||||||
|
|
||||||
# Display the item's informations
|
# Display the item's informations
|
||||||
if not options[:display].nil?
|
if not options[:display].nil?
|
||||||
cli.display(options[:display], options[:group], options[:type], options[:format])
|
cli.display(options[:display], options[:group], options[:type])
|
||||||
|
|
||||||
# Remove an item
|
# Remove an item
|
||||||
elsif not options[:remove].nil?
|
elsif not options[:remove].nil?
|
||||||
|
|
Loading…
Add table
Reference in a new issue