mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-18 17:10:04 +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
|
# Main
|
||||||
# --------------------------------------------------------- #
|
# --------------------------------------------------------- #
|
||||||
|
|
||||||
config = MPW::Config.new(options[:config])
|
config = MPW::Config.new(options[:config])
|
||||||
check_error = config.checkconfig
|
cli = MPW::Cli.new(config)
|
||||||
|
|
||||||
cli = MPW::Cli.new(config)
|
|
||||||
|
|
||||||
# Setup a 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)
|
cli.setup(lang)
|
||||||
elsif not config.check_gpg_key?
|
elsif not config.check_gpg_key?
|
||||||
cli.setup_gpg_key
|
cli.setup_gpg_key
|
||||||
|
|
|
@ -98,18 +98,19 @@ class Config
|
||||||
|
|
||||||
# Check the config file
|
# Check the config file
|
||||||
# @rtrn: true if the config file is correct
|
# @rtrn: true if the config file is correct
|
||||||
def checkconfig
|
def is_valid?
|
||||||
config = YAML::load_file(@config_file)
|
config = YAML::load_file(@config_file)
|
||||||
@key = config['config']['key']
|
@key = config['config']['key']
|
||||||
@lang = config['config']['lang']
|
@lang = config['config']['lang']
|
||||||
@wallet_dir = config['config']['wallet_dir']
|
@wallet_dir = config['config']['wallet_dir']
|
||||||
|
|
||||||
if @key.empty? or @wallet_dir.empty?
|
raise if @key.empty? or @wallet_dir.empty?
|
||||||
raise I18n.t('error.config.check')
|
|
||||||
end
|
|
||||||
I18n.locale = @lang.to_sym
|
I18n.locale = @lang.to_sym
|
||||||
rescue Exception => e
|
|
||||||
raise "#{I18n.t('error.config.check')}\n#{e}"
|
return true
|
||||||
|
rescue
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if private key exist
|
# Check if private key exist
|
||||||
|
|
|
@ -35,7 +35,8 @@ class Cli
|
||||||
I18n.locale = language.to_sym
|
I18n.locale = language.to_sym
|
||||||
|
|
||||||
@config.setup(key, lang, wallet_dir)
|
@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
|
puts "#{I18n.t('form.setup_config.valid')}".green
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
Loading…
Add table
Reference in a new issue