1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-10-27 10:43:20 +00:00

fix delete item

This commit is contained in:
nishiki 2015-02-01 12:35:42 +01:00
parent 446faf704e
commit 5ceb3cfbdb
3 changed files with 33 additions and 23 deletions

View file

@ -54,6 +54,19 @@ module MPW
return true
end
def delete
@id = nil
@name = nil
@group = nil
@host = nil
@protocol = nil
@user = nil
@password = nil
@port = nil
@created = nil
@last_edit = nil
end
def empty?
return @name.to_s.empty?
end

View file

@ -289,12 +289,12 @@ class Cli
# Remove an item
# @args: id -> the item's id
# force -> no resquest a validation
def remove(id, force=false)
def delete(id, force=false)
if not force
result = @mpw.search_by_id(id)
item = @mpw.search_by_id(id)
if result.length > 0
display_item(result)
if not item.nil?
display_item(item)
confirm = ask("#{I18n.t('form.delete.ask', id: id)} (y/N) ").to_s
if confirm =~ /^(y|yes|YES|Yes|Y)$/
@ -306,15 +306,13 @@ class Cli
end
if force
if @mpw.remove(id)
if @mpw.encrypt
sync
puts "#{I18n.t('form.delete.valid', id: id)}".green
else
puts "#{I18n.t('display.error')} #16: #{@mpw.error_msg}".red
end
item.delete
if @mpw.encrypt
sync
puts "#{I18n.t('form.delete.valid', id: id)}".green
else
puts I18n.t('form.delete.not_valid')
puts "#{I18n.t('display.error')} #16: #{@mpw.error_msg}".red
end
end
end
@ -327,7 +325,6 @@ class Cli
else
puts "#{I18n.t('display.error')} #17: #{@mpw.error_msg}".red
end
end
# Import items from a CSV file

20
mpw
View file

@ -43,21 +43,21 @@ options[:config] = nil
OptionParser.new do |opts|
opts.banner = "#{I18n.t('option.usage')}: mpw [options]"
opts.on('-d', '--display [SEARCH]', I18n.t('option.show')) do |search|
search.nil? ? (options[:display] = '') : (options[:display] = search)
opts.on('-s', '--show [SEARCH]', I18n.t('option.show')) do |search|
search.nil? ? (options[:show] = '') : (options[:show] = search)
end
opts.on('-A', '--show-all', I18n.t('option.show_all')) do
options[:type] = nil
options[:display] = ''
options[:type] = nil
options[:show] = ''
end
opts.on('-u', '--update ID', I18n.t('option.update')) do |id|
options[:update] = id
end
opts.on('-r', '--remove ID', I18n.t('option.remove')) do |id|
options[:remove] = id
opts.on('-d', '--delete ID', I18n.t('option.remove')) do |id|
options[:delete] = id
end
opts.on('-g', '--group GROUP', I18n.t('option.group')) do |group|
@ -128,12 +128,12 @@ cli.decrypt
cli.sync
# Display the item's informations
if not options[:display].nil?
cli.display(options[:display], options[:group], options[:type])
if not options[:show].nil?
cli.display(options[:show], options[:group], options[:type])
# Remove an item
elsif not options[:remove].nil?
cli.remove(options[:remove], options[:force])
elsif not options[:delete].nil?
cli.delete(options[:delete], options[:force])
# Update an item
elsif not options[:update].nil?