1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-27 07:33:05 +00:00

fix add item

This commit is contained in:
nishiki 2015-02-01 11:48:02 +01:00
parent 57b2ca5fca
commit 9921d3057f
2 changed files with 29 additions and 11 deletions

View file

@ -63,8 +63,8 @@ module MPW
def encrypt
FileUtils.cp(@file_gpg, "#{@file_gpg}.bk") if File.exist?(@file_gpg)
data_to_encrypt = {}
@data.each do |item|
puts item.class
next if item.empty?
data_to_encrypt.merge!(item.id => {'id' => item.id,
@ -101,6 +101,22 @@ module MPW
return false
end
# Add a new item
# @args: item -> Object MPW::Item
# @rtrn: true if add item
def add(item)
if not item.instance_of?(Item)
@error_msg = I18n.t('error.bad_class')
return false
elsif item.empty?
@error_msg = I18n.t('error.add.empty')
return false
else
@data.push(item)
return true
end
end
# Search in some csv data
# @args: search -> the string to search
# protocol -> the connection protocol (ssh, web, other)

View file

@ -224,19 +224,21 @@ class Cli
# Form to add a new item
def add
row = []
options = {}
puts I18n.t('form.add.title')
puts '--------------------'
name = ask(I18n.t('form.add.name')).to_s
group = ask(I18n.t('form.add.group')).to_s
server = ask(I18n.t('form.add.server')).to_s
protocol = ask(I18n.t('form.add.protocol')).to_s
login = ask(I18n.t('form.add.login')).to_s
passwd = ask(I18n.t('form.add.password')).to_s
port = ask(I18n.t('form.add.port')).to_s
comment = ask(I18n.t('form.add.comment')).to_s
options[:name] = ask(I18n.t('form.add.name')).to_s
options[:group] = ask(I18n.t('form.add.group')).to_s
options[:host] = ask(I18n.t('form.add.server')).to_s
options[:protocol] = ask(I18n.t('form.add.protocol')).to_s
options[:user] = ask(I18n.t('form.add.login')).to_s
options[:passwd] = ask(I18n.t('form.add.password')).to_s
options[:port] = ask(I18n.t('form.add.port')).to_s
options[:comment] = ask(I18n.t('form.add.comment')).to_s
if @mpw.update(name, group, server, protocol, login, passwd, port, comment)
item = MPW::Item.new(options)
if @mpw.add(item)
if @mpw.encrypt
sync
puts "#{I18n.t('form.add.valid')}".green