1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-23 13:57:52 +00:00

remove error_msg in config class

This commit is contained in:
nishiki 2016-05-15 18:30:33 +02:00
parent 68a0fddde8
commit a4fe063703
2 changed files with 23 additions and 45 deletions

View file

@ -19,7 +19,6 @@ class Config
# Constructor
# @args: config_file -> the specify config file
def initialize(config_file=nil)
@error_msg = nil
@config_file = config_file
if /darwin/ =~ RUBY_PLATFORM
@ -43,8 +42,7 @@ class Config
def setup(key, lang, wallet_dir)
if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
@error_msg = I18n.t('error.config.key_bad_format')
return false
raise I18n.t('error.config.key_bad_format')
end
if wallet_dir.empty?
@ -62,10 +60,8 @@ class Config
file << config.to_yaml
end
return true
rescue Exception => e
@error_msg = "#{I18n.t('error.config.write')}\n#{e}"
return false
raise "#{I18n.t('error.config.write')}\n#{e}"
end
# Setup a new gpg key
@ -76,11 +72,9 @@ class Config
# @rtrn: true if the GPG key is create, else false
def setup_gpg_key(password, name, length = 4096, expire = 0)
if name.nil? or name.empty?
@error_msg = "#{I18n.t('error.config.genkey_gpg.name')}"
return false
raise "#{I18n.t('error.config.genkey_gpg.name')}"
elsif password.nil? or password.empty?
@error_msg = "#{I18n.t('error.config.genkey_gpg.password')}"
return false
raise "#{I18n.t('error.config.genkey_gpg.password')}"
end
param = ''
@ -98,11 +92,8 @@ class Config
ctx = GPGME::Ctx.new
ctx.genkey(param, nil, nil)
return true
rescue Exception => e
@error_msg = "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
return false
raise "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
end
# Check the config file
@ -114,15 +105,11 @@ class Config
@wallet_dir = config['config']['wallet_dir']
if @key.empty? or @wallet_dir.empty?
@error_msg = I18n.t('error.config.check')
return false
raise I18n.t('error.config.check')
end
I18n.locale = @lang.to_sym
return true
rescue Exception => e
@error_msg = "#{I18n.t('error.config.check')}\n#{e}"
return false
raise "#{I18n.t('error.config.check')}\n#{e}"
end
# Check if private key exist
@ -148,11 +135,8 @@ class Config
File.open(@config_file, 'w') do |file|
file << config.to_yaml
end
return true
rescue Exception => e
@error_msg = "#{I18n.t('error.config.write')}\n#{e}"
return false
raise "#{I18n.t('error.config.write')}\n#{e}"
end
end

View file

@ -34,18 +34,14 @@ class Cli
end
I18n.locale = language.to_sym
if @config.setup(key, lang, wallet_dir)
puts "#{I18n.t('form.setup_config.valid')}".green
else
puts "#{I18n.t('display.error')} #8: #{@config.error_msg}".red
exit 2
end
@config.setup(key, lang, wallet_dir)
@config.checkconfig
if not @config.checkconfig
puts "#{I18n.t('display.error')} #9: #{@config.error_msg}".red
puts "#{I18n.t('form.setup_config.valid')}".green
rescue Exception => e
puts "#{I18n.t('display.error')} #8: #{e}".red
exit 2
end
end
# Setup a new GPG key
def setup_gpg_key
@ -54,8 +50,7 @@ class Cli
ask = ask(I18n.t('form.setup_gpg_key.ask')).to_s
if not ['Y', 'y', 'O', 'o'].include?(ask)
puts I18n.t('form.setup_gpg_key.no_create')
exit 2
raise I18n.t('form.setup_gpg_key.no_create')
end
name = ask(I18n.t('form.setup_gpg_key.name')).to_s
@ -63,8 +58,7 @@ class Cli
confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) {|q| q.echo = false}
if password != confirm
puts I18n.t('form.setup_gpg_key.error_password')
exit 2
raise I18n.t('form.setup_gpg_key.error_password')
end
length = ask(I18n.t('form.setup_gpg_key.length')).to_s
@ -76,13 +70,13 @@ class Cli
puts I18n.t('form.setup_gpg_key.wait')
if @config.setup_gpg_key(password, name, length, expire)
@config.setup_gpg_key(password, name, length, expire)
puts "#{I18n.t('form.setup_gpg_key.valid')}".green
else
puts "#{I18n.t('display.error')} #10: #{@config.error_msg}".red
rescue Exception => e
puts "#{I18n.t('display.error')} #8: #{e}".red
exit 2
end
end
# Setup wallet config for sync
def setup_wallet_config