1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-03-17 20:29:29 +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 return true
end 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? def empty?
return @name.to_s.empty? return @name.to_s.empty?
end end

View file

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

20
mpw
View file

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