mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-26 23:33:03 +00:00
rename function checkconfig to is_valid?
This commit is contained in:
parent
f842bd63ee
commit
2a0decd215
3 changed files with 12 additions and 12 deletions
8
bin/mpw
8
bin/mpw
|
@ -128,13 +128,11 @@ end.parse!
|
|||
# Main
|
||||
# --------------------------------------------------------- #
|
||||
|
||||
config = MPW::Config.new(options[:config])
|
||||
check_error = config.checkconfig
|
||||
|
||||
cli = MPW::Cli.new(config)
|
||||
config = MPW::Config.new(options[:config])
|
||||
cli = MPW::Cli.new(config)
|
||||
|
||||
# Setup a new config
|
||||
if not check_error or not options[:setup].nil?
|
||||
if not config.is_valid? or not options[:setup].nil?
|
||||
cli.setup(lang)
|
||||
elsif not config.check_gpg_key?
|
||||
cli.setup_gpg_key
|
||||
|
|
|
@ -98,18 +98,19 @@ class Config
|
|||
|
||||
# Check the config file
|
||||
# @rtrn: true if the config file is correct
|
||||
def checkconfig
|
||||
def is_valid?
|
||||
config = YAML::load_file(@config_file)
|
||||
@key = config['config']['key']
|
||||
@lang = config['config']['lang']
|
||||
@wallet_dir = config['config']['wallet_dir']
|
||||
|
||||
if @key.empty? or @wallet_dir.empty?
|
||||
raise I18n.t('error.config.check')
|
||||
end
|
||||
raise if @key.empty? or @wallet_dir.empty?
|
||||
|
||||
I18n.locale = @lang.to_sym
|
||||
rescue Exception => e
|
||||
raise "#{I18n.t('error.config.check')}\n#{e}"
|
||||
|
||||
return true
|
||||
rescue
|
||||
return false
|
||||
end
|
||||
|
||||
# Check if private key exist
|
||||
|
|
|
@ -35,7 +35,8 @@ class Cli
|
|||
I18n.locale = language.to_sym
|
||||
|
||||
@config.setup(key, lang, wallet_dir)
|
||||
@config.checkconfig
|
||||
|
||||
raise I18n.t('error.config.check') if not @config.is_valid?
|
||||
|
||||
puts "#{I18n.t('form.setup_config.valid')}".green
|
||||
rescue Exception => e
|
||||
|
|
Loading…
Reference in a new issue