1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-22 02:40:04 +00:00

cli: fix delete function

This commit is contained in:
nishiki 2016-05-05 23:24:08 +02:00
parent 38beb7ad53
commit 163ef46076

View file

@ -213,32 +213,29 @@ class Cli
# @args: id -> the item's id # @args: id -> the item's id
# force -> no resquest a validation # force -> no resquest a validation
def delete(id, force=false) def delete(id, force=false)
if not force
item = @mpw.search_by_id(id) item = @mpw.search_by_id(id)
if not item.nil? if item.nil?
puts I18n.t('display.nothing')
return
end
if not force
display_item(item) display_item(item)
confirm = ask("#{I18n.t('form.delete.ask', id: id)} (y/N) ").to_s confirm = ask("#{I18n.t('form.delete.ask', id: id)} (y/N) ").to_s
if confirm =~ /^(y|yes|YES|Yes|Y)$/ if not confirm =~ /^(y|yes|YES|Yes|Y)$/
force = true return
end
else
puts I18n.t('display.nothing')
end end
end end
if force
item.delete item.delete
@mpw.write_data
if @mpw.encrypt
sync
puts "#{I18n.t('form.delete.valid', id: id)}".green puts "#{I18n.t('form.delete.valid', id: id)}".green
else rescue
puts "#{I18n.t('display.error')} #16: #{@mpw.error_msg}".red puts "#{I18n.t('display.error')} #16: #{@mpw.error_msg}".red
end end
end
end
# Export the items in a CSV file # Export the items in a CSV file
# @args: file -> the destination file # @args: file -> the destination file