mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +00:00
init: iniatilize a default wallet
This commit is contained in:
parent
3fd70721f3
commit
e45c528a3f
3 changed files with 30 additions and 20 deletions
|
@ -60,11 +60,12 @@ OptionParser.new do |opts|
|
|||
end.parse!
|
||||
|
||||
config = MPW::Config.new(options[:config])
|
||||
cli = MPW::Cli.new(config, options[:clipboard], options[:sync], options[:otp])
|
||||
cli = MPW::Cli.new(config, nil, nil, nil)
|
||||
|
||||
if not options[:init].nil?
|
||||
cli.setup(options)
|
||||
cli.setup_gpg_key(options[:gpg_key]) if not config.check_gpg_key?
|
||||
cli.setup_wallet_config
|
||||
exit 0
|
||||
end
|
||||
|
||||
|
|
|
@ -89,9 +89,11 @@ class Cli
|
|||
raise I18n.t('form.setup_gpg_key.error_password')
|
||||
end
|
||||
|
||||
@password = password.to_s
|
||||
|
||||
puts I18n.t('form.setup_gpg_key.wait')
|
||||
|
||||
@config.setup_gpg_key(password.to_s, gpg_key)
|
||||
@config.setup_gpg_key(@password, gpg_key)
|
||||
|
||||
puts "#{I18n.t('form.setup_gpg_key.valid')}".green
|
||||
rescue Exception => e
|
||||
|
@ -100,23 +102,27 @@ class Cli
|
|||
end
|
||||
|
||||
# Setup wallet config for sync
|
||||
def setup_wallet_config
|
||||
config = {}
|
||||
config['sync'] = {}
|
||||
# @args: wallet -> the wallet name
|
||||
def setup_wallet_config(wallet = nil)
|
||||
#config = {}
|
||||
#config['sync'] = {}
|
||||
|
||||
puts I18n.t('form.setup_wallet.title')
|
||||
puts '--------------------'
|
||||
config['sync']['type'] = ask(I18n.t('form.setup_wallet.sync_type')).to_s
|
||||
#puts '--------------------'
|
||||
#config['sync']['type'] = ask(I18n.t('form.setup_wallet.sync_type')).to_s
|
||||
|
||||
if ['ftp', 'ssh'].include?(config['sync']['type'].downcase)
|
||||
config['sync']['host'] = ask(I18n.t('form.setup_wallet.sync_host')).to_s
|
||||
config['sync']['port'] = ask(I18n.t('form.setup_wallet.sync_port')).to_s
|
||||
config['sync']['user'] = ask(I18n.t('form.setup_wallet.sync_user')).to_s
|
||||
config['sync']['password'] = ask(I18n.t('form.setup_wallet.sync_pwd')).to_s
|
||||
config['sync']['path'] = ask(I18n.t('form.setup_wallet.sync_path')).to_s
|
||||
end
|
||||
#if ['ftp', 'ssh'].include?(config['sync']['type'].downcase)
|
||||
# config['sync']['host'] = ask(I18n.t('form.setup_wallet.sync_host')).to_s
|
||||
# config['sync']['port'] = ask(I18n.t('form.setup_wallet.sync_port')).to_s
|
||||
# config['sync']['user'] = ask(I18n.t('form.setup_wallet.sync_user')).to_s
|
||||
# config['sync']['password'] = ask(I18n.t('form.setup_wallet.sync_pwd')).to_s
|
||||
# config['sync']['path'] = ask(I18n.t('form.setup_wallet.sync_path')).to_s
|
||||
#end
|
||||
|
||||
@mpw.set_config(config)
|
||||
wallet_file = wallet.nil? ? "#{@config.wallet_dir}/default.mpw" : "#{@config.wallet_dir}/#{wallet}.mpw"
|
||||
|
||||
@mpw = MPW.new(@config.key, wallet_file, @password, @config.gpg_exe)
|
||||
@mpw.read_data
|
||||
@mpw.set_config
|
||||
@mpw.write_data
|
||||
|
||||
puts "#{I18n.t('form.setup_wallet.valid')}".green
|
||||
|
@ -384,7 +390,7 @@ class Cli
|
|||
@mpw.sync(true) if @sync
|
||||
|
||||
puts "#{I18n.t('form.add_item.valid')}".green
|
||||
rescue Exception => e
|
||||
#rescue Exception => e
|
||||
puts "#{I18n.t('display.error')} #13: #{e}".red
|
||||
end
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ class MPW
|
|||
|
||||
data.merge!(item.id => {'id' => item.id,
|
||||
'name' => item.name,
|
||||
'group' => item.group,
|
||||
'group' => item.group,
|
||||
'host' => item.host,
|
||||
'protocol' => item.protocol,
|
||||
'user' => item.user,
|
||||
|
@ -158,7 +158,7 @@ class MPW
|
|||
|
||||
File.rename(tmp_file, @wallet_file)
|
||||
rescue Exception => e
|
||||
File.unlink(tmp_file)
|
||||
File.unlink(tmp_file) if File.exist?(tmp_file)
|
||||
|
||||
raise "#{I18n.t('error.mpw_file.write_data')}\n#{e}"
|
||||
end
|
||||
|
@ -211,9 +211,12 @@ class MPW
|
|||
|
||||
# Set config
|
||||
# args: config -> a hash with config options
|
||||
def set_config(config)
|
||||
def set_config(config=nil)
|
||||
@config = {} if @config.nil?
|
||||
@config['sync'] = {} if @config['sync'].nil?
|
||||
|
||||
return if config.to_s.empty?
|
||||
|
||||
@config['sync']['type'] = config['sync']['type']
|
||||
@config['sync']['host'] = config['sync']['host']
|
||||
@config['sync']['port'] = config['sync']['port']
|
||||
|
|
Loading…
Add table
Reference in a new issue