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

replace if not by unless

This commit is contained in:
Adrien Waksberg 2017-03-27 22:31:05 +02:00
parent 7c72b2d90f
commit 178d0e6d1d
7 changed files with 17 additions and 23 deletions

View file

@ -66,7 +66,7 @@ cli = MPW::Cli.new(config)
cli.load_config
if not options[:list].nil?
if !options[:list].nil?
cli.list_wallet
else
cli.get_wallet(options[:wallet])

View file

@ -103,7 +103,7 @@ class Cli
# Request the GPG password and decrypt the file
def decrypt
if not defined?(@mpw)
unless defined?(@mpw)
@password = ask(I18n.t('display.gpg_password')) {|q| q.echo = false}
@mpw = MPW.new(@config.gpg_key, @wallet_file, @password, @config.gpg_exe)
end
@ -451,9 +451,7 @@ class Cli
item = get_item(items)
confirm = ask("#{I18n.t('form.delete_item.ask')} (y/N) ").to_s
if not confirm =~ /^(y|yes|YES|Yes|Y)$/
return false
end
return false unless confirm =~ /^(y|yes|YES|Yes|Y)$/
item.delete
@mpw.write_data
@ -516,7 +514,7 @@ class Cli
# @args: file -> the import file
def import(file)
raise I18n.t('form.import.file_empty') if file.to_s.empty?
raise I18n.t('form.import.file_not_exist') if not File.exist?(file)
raise I18n.t('form.import.file_not_exist') unless File.exist?(file)
YAML::load_file(file).each_value do |row|
item = Item.new(group: row['group'],
@ -530,8 +528,8 @@ class Cli
next if item.empty?
@mpw.add(item)
@mpw.set_password(item.id, row['password']) if not row['password'].to_s.empty?
@mpw.set_otp_key(item.id, row['otp_key']) if not row['otp_key'].to_s.empty?
@mpw.set_password(item.id, row['password']) unless row['password'].to_s.empty?
@mpw.set_otp_key(item.id, row['otp_key']) unless row['otp_key'].to_s.empty?
end
@mpw.write_data

View file

@ -73,7 +73,7 @@ class Config
end
end
if not gpg_key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
unless gpg_key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
raise I18n.t('error.config.key_bad_format')
end

View file

@ -68,7 +68,7 @@ class Item
@port = options[:port].to_i if options.has_key?(:port) and not options[:port].to_s.empty?
@otp = options[:otp] if options.has_key?(:otp)
@comment = options[:comment] if options.has_key?(:comment)
@last_edit = Time.now.to_i if not options.has_key?(:no_update_last_edit)
@last_edit = Time.now.to_i unless options.has_key?(:no_update_last_edit)
end
# Delete all data

View file

@ -33,7 +33,7 @@ class MPW
@gpg_exe = gpg_exe
@wallet_file = wallet_file
if not @gpg_exe.to_s.empty?
unless @gpg_exe.to_s.empty?
GPGME::Engine.set_info(GPGME::PROTOCOL_OpenPGP, @gpg_exe, "#{Dir.home}/.gnupg")
end
end
@ -48,7 +48,7 @@ class MPW
data = nil
return if not File.exists?(@wallet_file)
return unless File.exists?(@wallet_file)
Gem::Package::TarReader.new(File.open(@wallet_file)) do |tar|
tar.each do |f|
@ -80,7 +80,7 @@ class MPW
end
end
if not data.nil? and not data.empty?
unless data.to_s.empty?
YAML.load(data).each_value do |d|
@data.push(Item.new(id: d['id'],
group: d['group'],
@ -254,14 +254,12 @@ class MPW
@data.each do |item|
next if item.empty?
next if not group.empty? and not group.eql?(item.group.to_s.downcase)
next unless group.empty? or group.eql?(item.group.to_s.downcase)
host = item.host.to_s.downcase
comment = item.comment.to_s.downcase
if not host =~ /^.*#{search}.*$/ and not comment =~ /^.*#{search}.*$/
next
end
next unless host =~ /^.*#{search}.*$/ or comment =~ /^.*#{search}.*$/
result.push(item)
end
@ -284,9 +282,7 @@ class MPW
# args: id -> the item id
# key -> the new key
def set_otp_key(id, key)
if not key.to_s.empty?
@otp_keys[id] = encrypt(key.to_s)
end
@otp_keys[id] = encrypt(key.to_s) unless key.to_s.empty?
end
# Get an opt key
@ -305,7 +301,7 @@ class MPW
# @args: id -> the item id
# @rtrn: an otp code
def get_otp_code(id)
if not @otp_keys.has_key?(id)
unless @otp_keys.has_key?(id)
return 0
else
return ROTP::TOTP.new(decrypt(@otp_keys[id])).now

View file

@ -2,7 +2,7 @@
host: # <%= I18n.t('form.add_item.host') %>
user: # <%= I18n.t('form.add_item.login') %>
group: # <%= I18n.t('form.add_item.group') %>
protocol: # <%= I18n.t('form.add_item.protocol') %><% if not password %>
protocol: # <%= I18n.t('form.add_item.protocol') %><% unless password %>
password: # <%= I18n.t('form.add_item.password') %><% end %>
port: # <%= I18n.t('form.add_item.port') %>
comment: # <%= I18n.t('form.add_item.comment') %>

View file

@ -2,7 +2,7 @@
# <%= I18n.t('form.update_item.host') %>
host: <%= item.host %>
# <%= I18n.t('form.update_item.login') %>
user: <%= item.user %><% if not password %>
user: <%= item.user %><% unless password %>
# <%= I18n.t('form.update_item.password') %>
password: <% end %>
# <%= I18n.t('form.update_item.group') %>