From ec982ce4d80cb164350b1b45c8c1a0b2f0c899a3 Mon Sep 17 00:00:00 2001 From: nishiki Date: Thu, 12 May 2016 22:43:57 +0200 Subject: [PATCH] add function for setup wallet config --- bin/mpw | 9 ++++++++- lib/mpw/mpw.rb | 6 ++++++ lib/mpw/ui/cli.rb | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/bin/mpw b/bin/mpw index a185b49..830b2c2 100755 --- a/bin/mpw +++ b/bin/mpw @@ -2,7 +2,6 @@ # author: nishiki # mail: nishiki@yaegashi.fr -require 'rubygems' require 'optparse' require 'pathname' require 'locale' @@ -119,6 +118,10 @@ OptionParser.new do |opts| opts.on('-w', '--wallet WALLET', I18n.t('option.wallet')) do |wallet| options[:wallet] = wallet end + + opts.on('-W', '--setup-wallet', I18n.t('option.setup_wallet')) do + options[:setup_wallet] = true + end end.parse! # --------------------------------------------------------- # @@ -177,6 +180,10 @@ elsif not options[:export].nil? and not options[:file].nil? elsif not options[:import].nil? and not options[:file].nil? cli.import(options[:file]) +# Setup wallet config +elsif not options[:setup_wallet].nil? + cli.setup_wallet_config + end cli = nil diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb index 2c671a8..9ae896e 100644 --- a/lib/mpw/mpw.rb +++ b/lib/mpw/mpw.rb @@ -184,6 +184,12 @@ class MPW end end + # Set config + # args: config -> a hash with config options + def set_config(config) + @config = config + end + # Add a new item # @args: item -> Object MPW::Item def add(item) diff --git a/lib/mpw/ui/cli.rb b/lib/mpw/ui/cli.rb index a3b846b..ec99a7c 100644 --- a/lib/mpw/ui/cli.rb +++ b/lib/mpw/ui/cli.rb @@ -84,6 +84,26 @@ class Cli end end + # Setup wallet config for sync + def setup_wallet_config + config = {} + config['sync'] = {} + + puts I18n.t('form.setup.title') + puts '--------------------' + config['sync']['type'] = ask(I18n.t('form.setup.sync_type')).to_s + config['sync']['host'] = ask(I18n.t('form.setup.sync_host')).to_s + config['sync']['port'] = ask(I18n.t('form.setup.sync_port')).to_s + config['sync']['user'] = ask(I18n.t('form.setup.sync_user')).to_s + config['sync']['pwd'] = ask(I18n.t('form.setup.sync_pwd')).to_s + config['sync']['path'] = ask(I18n.t('form.setup.sync_path')).to_s + + @mpw.set_config(config) + @mpw.write_data + rescue Exception => e + puts "#{I18n.t('display.error')} #10: #{e}".red + exit 2 + end # Request the GPG password and decrypt the file def decrypt